Skip to content

Series.Str (SeriesStrNameSpace) ​

Namespace: Polars.FSharp

Instance Methods ​

Contains ​

Checks if the string contains the given pattern.

fsharp
member Contains(pattern: string, ?literal: bool, ?strict: bool) : Series

Parameters

NameTypeDescription
patternstringThe pattern to search for. Can be a literal string or a regex pattern.
literalbool (optional)If true, treat the pattern as a literal string (not a regex).
strictbool (optional)If true, throw an error if the pattern is not found.

Returns: An expression that returns a boolean indicating whether the pattern was found.


ContainsAny ​

Checks if the strings contain any of the given patterns.

fsharp
member ContainsAny(pattern: string, ?asciiCaseInsensitive: bool) : Series

Parameters

NameTypeDescription
patternstringThe pattern to search for. This is treated as a regex pattern.
asciiCaseInsensitivebool (optional)If true, perform case-insensitive matching for ASCII characters.

Returns: An expression that returns a boolean indicating whether any of the patterns were found.


CountMatches ​

Counts the number of non-overlapping matches of the pattern in the string.

fsharp
member CountMatches(pattern: string, ?literal: bool) : Series

Parameters

NameTypeDescription
patternstringThe pattern to search for. Can be a literal string or a regex pattern.
literalbool (optional)If true, treat the pattern as a literal string (not a regex).

Returns: An expression that returns the count of matches.


Decode ​

Decode a Bytes Series into a String Series, using the specified encoding.

fsharp
member Decode(encoding: TransferEncoding, ?strict: bool) : Series

Parameters

NameTypeDescription
encodingTransferEncodingThe Charset encoding to use for the conversion.
strictbool (optional)If true, invalid bytes will raise an exception. If false, they will be replaced with the replacement character.

Returns: An expression that converts the Bytes Series to a String Series.


Encode ​

Encode a String Series into a Bytes Series, using the specified encoding.

fsharp
member Encode(encoding: TransferEncoding) : Series

Parameters

NameTypeDescription
encodingTransferEncodingThe Charset encoding to use for the conversion.

Returns: An expression that converts the String Series to a Bytes Series.


EndsWith ​

Check if the string ends with the given suffix.

fsharp
member EndsWith(suffix: string) : Series

Parameters

NameTypeDescription
suffixstringThe suffix to check for.

Returns: An expression that returns true if the string ends with the suffix, false otherwise.


EscapeRegex ​

Returns string values with all regular expression meta characters escaped.

fsharp
member EscapeRegex : unit -> Series

Extract ​

Extract the target capture group from a regex pattern.

fsharp
member Extract(pattern: string, ?groupIndex: int) : Series

Parameters

NameTypeDescription
patternstringRegex pattern with capture groups.
groupIndexint (optional)The index of the capture group to extract (default is 1).

ExtractGroups ​

Extracts all matches for the given regex pattern.

fsharp
member ExtractGroups(pattern: string) : Series

Parameters

NameTypeDescription
patternstringA valid regular expression pattern, compatible with the regex crate.

Returns: An expression that, for each row, returns a list of all non-overlapping matches of the given regex pattern. If no match is found, an empty list is returned. If a row contains null, null is returned.


ExtractMany ​

Extracts all successive non-overlapping regex matches in an individual string as a list.

fsharp
member ExtractMany(
    patterns: Expr,
    ?asciiCaseInsensitive: bool,
    ?overlapping: bool,
    ?leftmost: bool
) : Series

Parameters

NameTypeDescription
patternsExprString patterns to search. This method supports matching on string literals only, and does not support regular expression matching.
asciiCaseInsensitivebool (optional)Enable ASCII-aware case-insensitive matching.
overlappingbool (optional)Whether matches may overlap.
leftmostbool (optional)Guarantees in case there are overlapping matches that the leftmost match is used.

Find ​

Return the bytes offset of the first substring matching a pattern. If the pattern is not found, returns None.

fsharp
member Find(pattern: string, ?literal: bool, ?strict: bool) : Series

Parameters

NameTypeDescription
patternstringA valid regular expression pattern, compatible with the regex crate.
literalbool (optional)Treat pattern as a literal string, not as a regular expression.
strictbool (optional)Raise an error if the underlying pattern is not a valid regex, otherwise mask out with a null value.

FindMany ​

Return the bytes offset of all non-overlapping substrings matching a pattern. If the pattern is not found, an empty list is returned.

fsharp
member FindMany(
    patterns: Expr,
    ?asciiCaseInsensitive: bool,
    ?overlapping: bool,
    ?leftmost: bool
) : Series

Parameters

NameTypeDescription
patternsExprAn expression yielding string patterns to search. This method supports matching on string literals only, and does not support regular expression matching.
asciiCaseInsensitivebool (optional)Enable ASCII-aware case-insensitive matching. When this option is enabled, searching will be performed without respect to case for ASCII letters (a-z and A-Z) only.
overlappingbool (optional)Whether matches may overlap. This is only supported when the search pattern contains a wildcard.
leftmostbool (optional)Guarantees in case there are overlapping matches that the leftmost match is used. In case there are multiple candidates for the leftmost match the pattern which comes first in patterns is used. May not be used together with overlapping = True.

Return the first n characters of the string.

fsharp
member Head(n: int) : Series

Parameters

NameTypeDescription
nintThe number of characters to return.

Returns: An expression that returns the first n characters of the string.


Join ​

Join elements of a string series with a separator.

fsharp
member Join(?delimiter: string, ?ignoreNulls: bool) : Series

Parameters

NameTypeDescription
delimiterstring (optional)The separator to use. Defaults to an empty string.
ignoreNullsbool (optional)Whether to ignore null values. Defaults to true.

Returns: An expression that joins the elements of the string series.


JsonDecode ​

Decode a String Series with JSON data into a structured Polars Series (e.g. List, Dict).

fsharp
member JsonDecode(dtype: DataType) : Series

Parameters

NameTypeDescription
dtypeDataTypeThe target DataType to decode the JSON into. This must be a structured type (e.g. DataType.List, DataType.Dict) as JSON decoding is not supported for primitive types like DataType.String or DataType.Int64.

Returns: A new Series with the decoded JSON data.


JsonPathMatch ​

Extracts all matches for the given JSONPath expression.

fsharp
member JsonPathMatch(jsonPath: string) : Series

Parameters

NameTypeDescription
jsonPathstringThe JSONPath expression to use for extraction.

Returns: An expression that returns a list of all matches for the given JSONPath expression.


LenBytes ​

Get length in bytes.

fsharp
member LenBytes : unit -> Series

LenChars ​

Return the length of each string as the number of characters.

fsharp
member LenChars : unit -> Series

Normalize ​

Returns the Unicode normal form of the string values.

fsharp
member Normalize(form: NormalizationForm) : Series

Parameters

NameTypeDescription
formNormalizationFormUnicode form to use.

PadEnd ​

Pad strings to a certain length by adding characters to the end.

fsharp
member PadEnd(length: int, ?fillChar: string) : Series

Parameters

NameTypeDescription
lengthintThe target length of the strings.
fillCharstring (optional)The character to pad with. Defaults to '0'.

Returns: An expression that pads the strings with trailing characters.


PadStart ​

Pad strings to a certain length by adding characters to the start.

fsharp
member PadStart(length: int, ?fillChar: string) : Series

Parameters

NameTypeDescription
lengthintThe target length of the strings.
fillCharstring (optional)The character to pad with. Defaults to '0'.

Returns: An expression that pads the strings with leading characters.


Replace ​

Replace the first occurrence of a substring or regex pattern with a new value.

fsharp
member Replace(
    pattern: string,
    value: string,
    ?literal: bool,
    ?n: int
) : Series

Parameters

NameTypeDescription
patternstringPattern to search for. Can be a literal string or a regex pattern.
valuestringString to replace the pattern with.
literalbool (optional)If true, treat pattern as a literal string (not a regex).
nint (optional)Maximum number of replacements (default is 1).

ReplaceAll ​

Replace all occurrences of a pattern with a new value.

fsharp
member ReplaceAll(pattern: string, value: string, ?literal: bool) : Series

Parameters

NameTypeDescription
patternstringPattern to search for. Can be a literal string or a regex pattern.
valuestringString to replace the pattern with.
literalbool (optional)If true, treat pattern as a literal string (not a regex).

ReplaceMany ​

Replace multiple patterns with different replacement values.

fsharp
member ReplaceMany(
    patterns: Expr,
    replaceWith: Expr,
    ?asciiCaseInsensitive: bool,
    ?leftmost: bool
) : Series

Parameters

NameTypeDescription
patternsExprExpression yielding string patterns to search and replace.
replaceWithExprStrings to replace where a pattern was a match. Length must match the length of patterns or have length 1. This can be broadcasted, so it supports many:one and many:many.
asciiCaseInsensitivebool (optional)Enable ASCII-aware case-insensitive matching.
leftmostbool (optional)Guarantees in case there are overlapping matches that the leftmost match is used.

Reverse ​

Reverses the order of the characters in each string.

fsharp
member Reverse : unit -> Series

Slice ​

Returns an expression that slices the string by an offset and a length.

fsharp
member Slice(offset: int64, ?length: uint64) : Series

Parameters

NameTypeDescription
offsetint64Start index.
lengthuint64 (optional)Length of the slice.

Split ​

Splits the string by separator and returns a List column.

fsharp
member Split(
    separator: string,
    ?inclusive: bool,
    ?literal: bool,
    ?strict: bool
) : Series

Parameters

NameTypeDescription
separatorstringThe separator to split by.
inclusivebool (optional)If true, include the separator in the result.
literalbool (optional)If true, treat the separator as a literal string (not a regex).
strictbool (optional)If true, throw an error if the separator is not found.

Returns: An expression that returns a List column of strings.


SplitExact ​

Split the string by a separator into a fixed number of pieces.

fsharp
member SplitExact(separator: string, n: int, ?inclusive: bool) : Series

Parameters

NameTypeDescription
separatorstringThe separator to split by.
nintThe number of pieces to split into.
inclusivebool (optional)If true, include the separator in the resulting pieces.

Returns: An expression that splits the string by the separator into a fixed number of pieces.


SplitN ​

Split the string by a separator.

fsharp
member SplitN(separator: string, n: int) : Series

Parameters

NameTypeDescription
separatorstringThe separator to split by.
nintThe maximum number of splits to perform.

Returns: An expression that splits the string by the separator.


StartsWith ​

Check if the string starts with the given prefix.

fsharp
member StartsWith(prefix: string) : Series

Parameters

NameTypeDescription
prefixstringThe prefix to check for.

Returns: An expression that returns true if the string starts with the prefix, false otherwise.


StripChars ​

Remove leading and trailing characters.

fsharp
member StripChars(?characters: string) : Series

Parameters

NameTypeDescription
charactersstring (optional)-

StripCharsEnd ​

Remove trailing characters.

fsharp
member StripCharsEnd(?characters: string) : Series

Parameters

NameTypeDescription
charactersstring (optional)-

StripCharsStart ​

Remove leading characters.

fsharp
member StripCharsStart(?characters: string) : Series

Parameters

NameTypeDescription
charactersstring (optional)-

StripPrefix ​

Remove the given prefix from the start of the string.

fsharp
member StripPrefix(prefix: string) : Series

Parameters

NameTypeDescription
prefixstringThe prefix to remove.

Returns: An expression that removes the prefix from the string.


StripSuffix ​

Remove the given suffix from the end of the string.

fsharp
member StripSuffix(suffix: string) : Series

Parameters

NameTypeDescription
suffixstringThe suffix to remove.

Returns: An expression that removes the suffix from the string.


Strptime ​

Parse string to datetime with given format.

fsharp
member Strptime(
    dtype: DataType,
    ?format: string,
    ?strict: bool,
    ?exact: bool,
    ?cache: bool,
    ?ambiguous: Expr
) : Series

Parameters

NameTypeDescription
dtypeDataTypeData type.
formatstring (optional)Date format.
strictbool (optional)Return null when parsing fails.
exactbool (optional)Return null when parsing fails.
cachebool (optional)Use cache.
ambiguousExpr (optional)Ambiguous dates.

Returns: Series of Datetime.


Tail ​

Return the last n characters of the string.

fsharp
member Tail(n: int) : Series

Parameters

NameTypeDescription
nintThe number of characters to return.

Returns: An expression that returns the last n characters of the string.


ToDate ​

Parse string to Date.

fsharp
member ToDate(
    ?format: string,
    ?strict: bool,
    ?exact: bool,
    ?cache: bool
) : Series

Parameters

NameTypeDescription
formatstring (optional)-
strictbool (optional)-
exactbool (optional)-
cachebool (optional)-

ToDatetime ​

Parse string to Datetime.

fsharp
member ToDatetime(
    ?format: string,
    ?timeUnit: TimeUnit,
    ?timeZone: string,
    ?strict: bool,
    ?exact: bool,
    ?cache: bool,
    ?ambiguous: Expr
) : Series

Parameters

NameTypeDescription
formatstring (optional)Date format.
timeUnitTimeUnit (optional)Time unit.
timeZonestring (optional)Time zone.
strictbool (optional)Return null when parsing fails.
exactbool (optional)Return null when parsing fails.
cachebool (optional)Use cache.
ambiguousExpr (optional)Ambiguous dates.

Returns: Series of Datetime.


ToDecimal ​

Convert string column to decimal.

fsharp
member ToDecimal(scale: int) : Series

Parameters

NameTypeDescription
scaleintScale of the decimal.

Returns: Series of decimal.


ToInteger ​

Convert string column to integer.

fsharp
member ToInteger(?radix: int, ?dtype: DataType, ?strict: bool) : Series

Parameters

NameTypeDescription
radixint (optional)Radix of the integer.
dtypeDataType (optional)Data type of the integer.
strictbool (optional)Return null when parsing fails.

Returns: Series of integer.


ToLowercase ​

Convert to lowercase.

fsharp
member ToLowercase : unit -> Series

ToTime ​

Parse string to Time.

fsharp
member ToTime(
    ?format: string,
    ?strict: bool,
    ?exact: bool,
    ?cache: bool
) : Series

Parameters

NameTypeDescription
formatstring (optional)Date format.
strictbool (optional)Return null when parsing fails.
exactbool (optional)Return null when parsing fails.
cachebool (optional)Use cache.

Returns: Series of Time.


ToTitlecase ​

Modify strings to their titlecase equivalent.

This is a form of case transform where the first letter of each word is capitalized, with the rest of the word in lowercase. Non-alphanumeric characters define the word boundaries.

fsharp
member ToTitlecase : unit -> Series

ToUppercase ​

Convert to uppercase.

fsharp
member ToUppercase : unit -> Series

Zfill ​

Pad strings with leading zeros until they reach the specified length.

fsharp
member Zfill(length: int) : Series

Parameters

NameTypeDescription
lengthintThe target length of the strings.

Returns: An expression that pads the strings with leading zeros.


Released under the MIT License. Powered by the Polars Rust core & Apache Arrow.