tidypolars.stringr

Module Contents

Functions

paste(*args[, sep])

Concatenate strings together

paste0(*args)

Concatenate strings together with no separator

str_c(*args[, sep])

Concatenate strings together

str_detect(string, pattern[, negate])

Detect the presence or absence of a pattern in a string

str_ends(string, pattern[, negate])

Detect the presence or absence of a pattern at the end of a string.

str_extract(string, pattern)

Extract the target capture group from provided patterns

str_length(string)

Length of a string

str_starts(string, pattern[, negate])

Detect the presence or absence of a pattern at the beginning of a string.

str_sub(string[, start, end])

Extract portion of string based on start and end inputs

str_remove_all(string, pattern)

Removes all matched patterns in a string

str_remove(string, pattern)

Removes the first matched patterns in a string

str_replace_all(string, pattern, replacement)

Replaces all matched patterns in a string

str_replace(string, pattern, replacement)

Replaces the first matched patterns in a string

str_to_lower(string)

Convert case of a string

str_to_upper(string)

Convert case of a string

str_trim(string[, side])

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')))
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')))
str_trim(string, side='both')[source]

Trim whitespace

Parameters:
  • string (Expr, Series) – Column or series to operate on

  • side (str) –

    One of:
    • ”both”

    • ”left”

    • ”right”

Examples

>>> df = tp.Tibble(x = [' a ', ' b ', ' c '])
>>> df.mutate(x = tp.str_trim(col('x')))