tidypolars_extra.stringr¶
Functions¶
|
Concatenate strings together |
|
Concatenate strings together with no separator |
|
Concatenate strings together. |
|
Count occurrences of a pattern in a string |
|
Detect the presence or absence of a pattern in a string |
|
Duplicate/repeat a string |
|
Detect the presence or absence of a pattern at the end of a string. |
|
Extract the target capture group from provided patterns |
|
Extract all matches of a pattern |
|
Length of a string |
|
Pad a string to a specified width |
|
Removes the first matched patterns in a string |
|
Removes all matched patterns in a string |
|
Replaces the first matched patterns in a string |
|
Replaces all matched patterns in a string |
|
Split a string by a pattern |
|
Remove leading/trailing whitespace and collapse internal whitespace |
|
Detect the presence or absence of a pattern at the beginning of a string. |
|
Extract portion of string based on start and end inputs |
|
Convert case of a string |
|
Convert string to Title Case |
|
Convert case of a string |
|
Trim whitespace |
|
Split string |
Module Contents¶
- tidypolars_extra.stringr.paste(*args, sep=' ')[source]¶
Concatenate strings together
- Parameters:
args (Expr, str) – Columns and or strings to concatenate
Examples
>>> df = tp.tibble(x = ['a', 'b', 'c']) >>> df.mutate(x_end = tp.paste(col('x'), 'end', sep = '_'))
- tidypolars_extra.stringr.paste0(*args)[source]¶
Concatenate strings together with no separator
- Parameters:
args (Expr, str) – Columns and or strings to concatenate
Examples
>>> df = tp.tibble(x = ['a', 'b', 'c']) >>> df.mutate(xend = tp.paste0(col('x'), 'end'))
- tidypolars_extra.stringr.str_c(*args, sep='')[source]¶
Concatenate strings together.
Alias for
paste().- Parameters:
args (Expr, str) – Columns and/or strings to concatenate
Examples
>>> df = tp.tibble(x = ['a', 'b', 'c']) >>> df.mutate(x_end = str_c(col('x'), 'end', sep = '_'))
- tidypolars_extra.stringr.str_count(string, pattern)[source]¶
Count occurrences of a pattern in a string
- Parameters:
string (Expr, str) – Column to operate on
pattern (str) – Regular expression pattern to count
Examples
>>> df.mutate(n = tp.str_count('x', 'a'))
- tidypolars_extra.stringr.str_detect(string, pattern, negate=False)[source]¶
Detect the presence or absence of a pattern in a string
- Parameters:
string (str) – Input series to operate on
pattern (str) – Pattern to look for
negate (bool) – If True, return non-matching elements
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_detect('name', 'a')) >>> df.mutate(x = str_detect('name', ['a', 'e']))
- tidypolars_extra.stringr.str_dup(string, times)[source]¶
Duplicate/repeat a string
- Parameters:
string (Expr, str) – Column to operate on
times (int) – Number of times to repeat
Examples
>>> df.mutate(repeated = tp.str_dup('x', 3))
- tidypolars_extra.stringr.str_ends(string, pattern, negate=False)[source]¶
Detect the presence or absence of a pattern at the end of a string.
- Parameters:
string (Expr) – Column to operate on
pattern (str) – Pattern to look for
negate (bool) – If True, return non-matching elements
Examples
>>> df = tp.tibble(words = ['apple', 'bear', 'amazing']) >>> df.filter(tp.str_ends(col('words'), 'ing'))
- tidypolars_extra.stringr.str_extract(string, pattern)[source]¶
Extract the target capture group from provided patterns
- Parameters:
string (str) – Input series to operate on
pattern (str) – Pattern to look for
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_extract(col('name'), 'e'))
- tidypolars_extra.stringr.str_extract_all(string, pattern)[source]¶
Extract all matches of a pattern
- Parameters:
string (Expr, str) – Column to operate on
pattern (str) – Regular expression pattern with capture group
- Returns:
A list column with all matches.
- Return type:
Expr
Examples
>>> df.mutate(matches = tp.str_extract_all('x', r'\d+'))
- tidypolars_extra.stringr.str_length(string)[source]¶
Length of a string
- Parameters:
string (str) – Input series to operate on
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_length(col('name')))
- tidypolars_extra.stringr.str_pad(string, width, side='left', pad=' ')[source]¶
Pad a string to a specified width
- Parameters:
string (Expr, str) – Column to operate on
width (int) – Minimum width of resulting string
side (str) – Side to pad on: ‘left’, ‘right’, or ‘both’
pad (str) – Character to pad with (single character)
Examples
>>> df.mutate(padded = tp.str_pad('x', 10))
- tidypolars_extra.stringr.str_remove(string, pattern)[source]¶
Removes the first matched patterns in a string
- Parameters:
string (str) – Input series to operate on
pattern (str) – Pattern to look for
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_remove(col('name'), 'a'))
- tidypolars_extra.stringr.str_remove_all(string, pattern)[source]¶
Removes all matched patterns in a string
- Parameters:
string (str) – Input series to operate on
pattern (str) – Pattern to look for
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_remove_all(col('name'), 'a'))
- tidypolars_extra.stringr.str_replace(string, pattern, replacement)[source]¶
Replaces the first matched patterns in a string
- Parameters:
string (str) – Input series to operate on
pattern (str) – Pattern to look for
replacement (str) – String that replaces anything that matches the pattern
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_replace(col('name'), 'a', 'A'))
- tidypolars_extra.stringr.str_replace_all(string, pattern, replacement)[source]¶
Replaces all matched patterns in a string
- Parameters:
string (str) – Input series to operate on
pattern (str) – Pattern to look for
replacement (str) – String that replaces anything that matches the pattern
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_replace_all(col('name'), 'a', 'A'))
- tidypolars_extra.stringr.str_split(string, pattern)[source]¶
Split a string by a pattern
- Parameters:
string (Expr, str) – Column to operate on
pattern (str) – Pattern to split on
- Returns:
A list column with split parts.
- Return type:
Expr
Examples
>>> df.mutate(parts = tp.str_split('x', '_'))
- tidypolars_extra.stringr.str_squish(string)[source]¶
Remove leading/trailing whitespace and collapse internal whitespace
- Parameters:
string (Expr, str) – Column to operate on
Examples
>>> df.mutate(clean = tp.str_squish('x'))
- tidypolars_extra.stringr.str_starts(string, pattern, negate=False)[source]¶
Detect the presence or absence of a pattern at the beginning of a string.
- Parameters:
string (Expr) – Column to operate on
pattern (str) – Pattern to look for
negate (bool) – If True, return non-matching elements
Examples
>>> df = tp.tibble(words = ['apple', 'bear', 'amazing']) >>> df.filter(tp.str_starts(col('words'), 'a'))
- tidypolars_extra.stringr.str_sub(string, start=0, end=None)[source]¶
Extract portion of string based on start and end inputs
- Parameters:
string (str) – Input series to operate on
start (int) – First position of the character to return
end (int) – Last position of the character to return
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_sub(col('name'), 0, 3))
- tidypolars_extra.stringr.str_to_lower(string)[source]¶
Convert case of a string
- Parameters:
string (str) – Convert case of this string
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_to_lower(col('name')))
- tidypolars_extra.stringr.str_to_title(string)[source]¶
Convert string to Title Case
- Parameters:
string (Expr, str) – Column to operate on
Examples
>>> df.mutate(titled = tp.str_to_title('x'))
- tidypolars_extra.stringr.str_to_upper(string)[source]¶
Convert case of a string
- Parameters:
string (str) – Convert case of this string
Examples
>>> df = tp.tibble(name = ['apple', 'banana', 'pear', 'grape']) >>> df.mutate(x = str_to_upper(col('name')))