tidypolars.stringr
¶
Module Contents¶
Functions¶
|
Concatenate strings together |
|
Concatenate strings together with no separator |
|
Concatenate strings together |
|
Detect the presence or absence of a pattern in a string |
|
Detect the presence or absence of a pattern at the end of a string. |
|
Extract the target capture group from provided patterns |
|
Length of a string |
|
Detect the presence or absence of a pattern at the beginning of a string. |
|
Extract portion of string based on start and end inputs |
|
Removes all matched patterns in a string |
|
Removes the first matched patterns in a string |
|
Replaces all matched patterns in a string |
|
Replaces the first matched patterns in a string |
|
Convert case of a string |
|
Convert case of a string |
|
Trim whitespace |
- 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 = '_'))
- 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'))
- str_c(*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 = str_c(col('x'), 'end', sep = '_'))
- 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']))
- 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'))
- 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'))
- 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')))
- 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'))
- 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))
- 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'))
- 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'))
- 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'))
- 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'))
- 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')))