Optional
ignoreNulls: booleanCheck if strings in Series contain a substring that matches a pattern.
A valid regular expression pattern, compatible with the regex crate @param literal Treat
pattern` as a literal string, not as a regular expression.
Raise an error if the underlying pattern is not a valid regex, otherwise mask out with a null value.
Boolean mask
const df = pl.DataFrame({"txt": ["Crab", "cat and dog", "rab$bit", null]})
df.select(
... pl.col("txt"),
... pl.col("txt").str.contains("cat|bit").alias("regex"),
... pl.col("txt").str.contains("rab$", true).alias("literal"),
... )
shape: (4, 3)
┌─────────────┬───────┬─────────┐
│ txt ┆ regex ┆ literal │
│ --- ┆ --- ┆ --- │
│ str ┆ bool ┆ bool │
╞═════════════╪═══════╪═════════╡
│ Crab ┆ false ┆ false │
│ cat and dog ┆ true ┆ false │
│ rab$bit ┆ true ┆ true │
│ null ┆ null ┆ null │
└─────────────┴───────┴─────────┘
Decodes a value using the provided encoding
hex | base64
Optional
strict: booleanhow to handle invalid inputs
- true: method will throw error if unable to decode a value
- false: unhandled values will be replaced with `null`
Encodes a value using the provided encoding
hex | base64
Extract the target capture group from provided patterns.
A valid regex pattern
Index of the targeted capture group. Group 0 mean the whole pattern, first group begin at index 1 Default to the first capture group
Utf8 array. Contain null if original value is null or regex capture nothing.
> df = pl.DataFrame({
... 'a': [
... 'http://vote.com/ballon_dor?candidate=messi&ref=polars',
... 'http://vote.com/ballon_dor?candidat=jorginho&ref=polars',
... 'http://vote.com/ballon_dor?candidate=ronaldo&ref=polars'
... ]})
> df.select(pl.col('a').str.extract(/candidate=(\w+)/, 1))
shape: (3, 1)
┌─────────┐
│ a │
│ --- │
│ str │
╞═════════╡
│ messi │
├╌╌╌╌╌╌╌╌╌┤
│ null │
├╌╌╌╌╌╌╌╌╌┤
│ ronaldo │
└─────────┘
Extract the first match of json string with provided JSONPath expression. Throw errors if encounter invalid json strings. All return value will be casted to Utf8 regardless of the original value.
A valid JSON path query string
Utf8 array. Contain null if original value is null or the jsonPath
return nothing.
Get length of the string values in the Series.
Remove leading whitespace.
Remove trailing whitespace.
Create subslices of the string values of a Utf8 Series.
Start of the slice (negative indexing may be used).
Optional
length: numberOptional length of the slice.
Split a string into substrings using the specified separator and return them as a Series.
— A string that identifies character or characters to use in separating the string.
Optional
options: boolean | { inclusive?: boolean }Optional
inclusive?: booleanInclude the split character/string in the results
Remove leading and trailing whitespace.
Parse a Series of dtype Utf8 to a Date/Datetime Series.
Date or Datetime.
Calendar date and time type
Optional
timeUnit: TimeUnit | "ms" | "ns" | "us"any of 'ms' | 'ns' | 'us'
timezone string as defined by Intl.DateTimeFormat America/New_York
for example.
Optional
fmt: stringformatting syntax. Read more
Modify the strings to their lowercase equivalent.
Modify the strings to their uppercase equivalent.
Vertically concat the values in the Series to a single string value.