tidypolars_extra.stringr

Functions

paste(*args[, sep])

Concatenate strings together

paste0(*args)

Concatenate strings together with no separator

str_c(*args[, sep])

Concatenate strings together.

str_count(string, pattern)

Count occurrences of a pattern in a string

str_detect(string, pattern[, negate])

Detect the presence or absence of a pattern in a string

str_dup(string, times)

Duplicate/repeat 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_extract_all(string, pattern)

Extract all matches of a pattern

str_length(string)

Length of a string

str_pad(string, width[, side, pad])

Pad a string to a specified width

str_remove(string, pattern)

Removes the first matched patterns in a string

str_remove_all(string, pattern)

Removes all matched patterns in a string

str_replace(string, pattern, replacement)

Replaces the first matched patterns in a string

str_replace_all(string, pattern, replacement)

Replaces all matched patterns in a string

str_split(string, pattern)

Split a string by a pattern

str_squish(string)

Remove leading/trailing whitespace and collapse internal whitespace

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_to_lower(string)

Convert case of a string

str_to_title(string)

Convert string to Title Case

str_to_upper(string)

Convert case of a string

str_trim(string[, side])

Trim whitespace

str_wrap(string, width[, sep])

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')))
tidypolars_extra.stringr.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')))
tidypolars_extra.stringr.str_wrap(string, width, sep='list')[source]

Split string

Parameters:
  • string (str) – Column name to operate on

  • width (int) – Width to split the string

  • sep (string) – One of “n”: put “n” to split the string; return a single string “list”: return a list based on width