Skip to main content

StringAccessor

Struct StringAccessor 

Source
pub struct StringAccessor<'a> { /* private fields */ }
Expand description

Created by Series::str(). Provides string manipulation methods analogous to pandas Series.str namespace.

Implementations§

Source§

impl StringAccessor<'_>

Source

pub fn lower(&self) -> Result<Series, FrameError>

Convert strings to lowercase.

Source

pub fn upper(&self) -> Result<Series, FrameError>

Convert strings to uppercase.

Source

pub fn strip(&self) -> Result<Series, FrameError>

Strip leading and trailing whitespace.

Source

pub fn strip_chars(&self, to_strip: &str) -> Result<Series, FrameError>

Strip leading and trailing characters in to_strip.

Matches pd.Series.str.strip(chars).

Source

pub fn lstrip(&self) -> Result<Series, FrameError>

Strip leading whitespace.

Source

pub fn lstrip_chars(&self, to_strip: &str) -> Result<Series, FrameError>

Strip leading characters in to_strip.

Matches pd.Series.str.lstrip(chars).

Source

pub fn rstrip(&self) -> Result<Series, FrameError>

Strip trailing whitespace.

Source

pub fn rstrip_chars(&self, to_strip: &str) -> Result<Series, FrameError>

Strip trailing characters in to_strip.

Matches pd.Series.str.rstrip(chars).

Source

pub fn contains(&self, pat: &str) -> Result<Series, FrameError>

Check whether each string contains a pattern.

Source

pub fn contains_any(&self, pats: &[&str]) -> Result<Series, FrameError>

Check whether each string contains any of the given patterns.

Matches pd.Series.str.contains('|'.join(pats), regex=True) but for literals.

Source

pub fn contains_with_options( &self, pat: &str, case: bool, na: Option<bool>, regex: bool, ) -> Result<Series, FrameError>

Check whether each string contains pat with case/na/regex options.

Matches pd.Series.str.contains(pat, case=True, na=None, regex=True):

  • regex=true treats pat as a regular expression; regex=false treats it as a literal substring search.
  • case=false makes the match case-insensitive.
  • na=None propagates nulls as NaN; na=Some(bool) replaces null entries with that boolean, matching pandas’ fill-on-NaN behavior.
Source

pub fn replace(&self, pat: &str, repl: &str) -> Result<Series, FrameError>

Replace occurrences of a pattern with a replacement string.

Source

pub fn replace_with_options( &self, pat: &str, repl: &str, n: Option<usize>, case: bool, regex: bool, ) -> Result<Series, FrameError>

Replace with pandas-parity case/regex/n options.

Matches pd.Series.str.replace(pat, repl, n=-1, case=True, regex=True):

  • regex=true compiles pat as a regex; regex=false treats it as a literal substring.
  • case=false performs case-insensitive matching. For literal mode this is implemented via case-folded find scanning.
  • n=None (pandas -1) replaces every occurrence. n=Some(k) caps at the first k replacements per cell.
Source

pub fn startswith(&self, pat: &str) -> Result<Series, FrameError>

Check whether each string starts with a prefix.

Source

pub fn startswith_any(&self, pats: &[&str]) -> Result<Series, FrameError>

Check whether each string starts with any of the given prefixes.

Matches pd.Series.str.startswith((p1, p2, ...)).

Source

pub fn startswith_with_na( &self, pat: &str, na: Option<bool>, ) -> Result<Series, FrameError>

Check whether each string starts with pat, replacing nulls with na.

Matches pd.Series.str.startswith(pat, na=...). When na is None (Rust None), nulls propagate as NaN — same as the default pandas behavior on 2.2+. When na is Some(true) / Some(false), null entries are replaced with that boolean.

Source

pub fn startswith_any_with_na( &self, pats: &[&str], na: Option<bool>, ) -> Result<Series, FrameError>

Check whether each string starts with any of pats, replacing nulls with na.

Matches pd.Series.str.startswith((p1, p2, ...), na=...).

Source

pub fn endswith(&self, pat: &str) -> Result<Series, FrameError>

Check whether each string ends with a suffix.

Source

pub fn endswith_any(&self, pats: &[&str]) -> Result<Series, FrameError>

Check whether each string ends with any of the given suffixes.

Matches pd.Series.str.endswith((s1, s2, ...)).

Source

pub fn endswith_with_na( &self, pat: &str, na: Option<bool>, ) -> Result<Series, FrameError>

Check whether each string ends with pat, replacing nulls with na.

Matches pd.Series.str.endswith(pat, na=...).

Source

pub fn endswith_any_with_na( &self, pats: &[&str], na: Option<bool>, ) -> Result<Series, FrameError>

Check whether each string ends with any of pats, replacing nulls with na.

Matches pd.Series.str.endswith((s1, s2, ...), na=...).

Source

pub fn len(&self) -> Result<Series, FrameError>

Get the length of each string (character count, not byte count).

Per br-frankenpandas-rg8ys.6.6: pandas returns float64 (not int64) to represent nullable integers. Nulls become NaN.

Source

pub fn slice( &self, start: Option<i64>, stop: Option<i64>, step: Option<i64>, ) -> Result<Series, FrameError>

Slice each string from start to end.

Source

pub fn slice_replace( &self, start: Option<i64>, stop: Option<i64>, repl: &str, ) -> Result<Series, FrameError>

Replace a positional slice of each string.

Matches pd.Series.str.slice_replace(start, stop, repl), including Python-style NEGATIVE start/stop. The replaced span is chars[start..] up to chars[max(start, stop)..], i.e. s[:start] + repl + s[stop:] with stop never preceding start. Verified vs live pandas 2.2.3: “abcde”.slice_replace(-2, None, “X”) -> “abcX”; .slice_replace(0, -1, “X”) -> “Xe”; .slice_replace(3, 1, “X”) -> “abcXde”.

Source

pub fn split_get(&self, pat: &str, n: i64) -> Result<Series, FrameError>

Split each string by a separator and return the n-th element.

Source

pub fn rsplit_get(&self, pat: &str, n: i64) -> Result<Series, FrameError>

Split each string from the right and return the n-th element.

Matches pd.Series.str.rsplit(pat).str[n].

Source

pub fn split_df(&self, pat: &str) -> Result<DataFrame, FrameError>

Split each string by a separator and return a DataFrame.

Matches pd.Series.str.split(pat, expand=True).

Source

pub fn split_df_n( &self, pat: &str, n: Option<usize>, ) -> Result<DataFrame, FrameError>

Split each string with a maximum number of splits, returning a DataFrame.

Matches pd.Series.str.split(pat, n=..., expand=True). n=None means split on every occurrence (default behavior); n=Some(k) caps the result at k + 1 parts by doing at most k splits.

Source

pub fn rsplit_df( &self, pat: &str, n: Option<usize>, ) -> Result<DataFrame, FrameError>

Split each string from the right and return a DataFrame.

Matches pd.Series.str.rsplit(pat, expand=True).

Source

pub fn split_count(&self, pat: &str) -> Result<Series, FrameError>

Count the number of parts when splitting by pattern.

Matches pd.Series.str.split(pat).str.len(). Returns Int64 count.

Source

pub fn join(&self, from: &str, sep: &str) -> Result<Series, FrameError>

Join/concatenate each string element with a separator.

Applies to each element: useful after conceptual split operations. Replaces occurrences of from with sep.

Source

pub fn capitalize(&self) -> Result<Series, FrameError>

Capitalize the first character and lowercase the rest (pandas behavior).

Source

pub fn title(&self) -> Result<Series, FrameError>

Title case each string.

Source

pub fn repeat(&self, n: usize) -> Result<Series, FrameError>

Repeat each string n times.

Source

pub fn pad( &self, width: usize, side: &str, fillchar: char, ) -> Result<Series, FrameError>

Pad strings to a minimum width with a fill character.

Source

pub fn contains_regex(&self, pat: &str) -> Result<Series, FrameError>

Check whether each string matches a regex pattern.

Analogous to pandas.Series.str.contains(pat, regex=True).

Source

pub fn replace_regex(&self, pat: &str, repl: &str) -> Result<Series, FrameError>

Replace first occurrence of a regex pattern with a replacement string.

Analogous to pandas.Series.str.replace(pat, repl, regex=True). The replacement string supports backreferences ($1, $2, etc.).

Source

pub fn replace_regex_all( &self, pat: &str, repl: &str, ) -> Result<Series, FrameError>

Replace all occurrences of a regex pattern with a replacement string.

Analogous to pandas.Series.str.replace(pat, repl, regex=True, n=-1).

Source

pub fn extract(&self, pat: &str) -> Result<Series, FrameError>

Extract the first match of a regex capture group.

Analogous to pandas.Series.str.extract(pat, expand=False) for a single-group pattern. Returns the first capture group (group 1) if the pattern contains a group, otherwise returns the full match (group 0). Non-matching strings produce Null. If the pattern’s single capture group is named, the group name is used as the Series name (matching pandas 2.2 behavior).

Source

pub fn extract_df(&self, pat: &str) -> Result<DataFrame, FrameError>

Extract multiple capture groups as a DataFrame.

Matches pd.Series.str.extract(pat) when pat has multiple groups.

Source

pub fn count(&self, pat: &str) -> Result<Series, FrameError>

Count occurrences of pattern in each string.

Matches pd.Series.str.count(pat).

Source

pub fn extract_to_frame(&self, pat: &str) -> Result<DataFrame, FrameError>

Extract capture groups from a regex, returning a DataFrame.

Analogous to pandas.Series.str.extract(pat, expand=True). Returns a DataFrame where each column corresponds to a capture group. If the pattern has named groups (?P<name>...), those names become column names; otherwise columns are numbered “0”, “1”, etc. Non-matching rows produce NaN in every group column.

Source

pub fn extractall(&self, pat: &str) -> Result<DataFrame, FrameError>

Extract all matches of a regex capture group, returning a DataFrame.

Analogous to pandas.Series.str.extractall(pat). Returns a DataFrame where each row is a match, with a composite index “original_idx, match_n”. If the pattern contains capture groups, returns one column per group. Named capture groups ((?P<name>...) / (?<name>...)) produce columns with that name; unnamed groups use positional names 0, 1, ....

Source

pub fn split_expand(&self, pat: &str) -> Result<DataFrame, FrameError>

Split strings by pattern, expanding into a DataFrame.

Analogous to pandas.Series.str.split(pat, expand=True). Returns a DataFrame where each column is a split part. Shorter splits are padded with NaN.

Source

pub fn split_expand_n( &self, pat: &str, n: Option<usize>, ) -> Result<DataFrame, FrameError>

Split strings by pattern with an optional split limit, expanding into a DataFrame.

Analogous to pandas.Series.str.split(pat, n=..., expand=True). Shorter splits are padded with NaN.

Source

pub fn count_matches(&self, pat: &str) -> Result<Series, FrameError>

Count non-overlapping matches of a regex pattern in each string.

Analogous to pandas.Series.str.count(pat).

Source

pub fn count_literal(&self, pat: &str) -> Result<Series, FrameError>

Count non-overlapping occurrences of a literal substring.

Matches pd.Series.str.count(pat) for literal patterns.

Source

pub fn findall(&self, pat: &str, sep: &str) -> Result<Series, FrameError>

Find all non-overlapping matches and return them joined by a separator.

Since Series cannot hold list values, matches are joined with sep. Non-matching strings produce Null.

Source

pub fn fullmatch(&self, pat: &str) -> Result<Series, FrameError>

Check whether each string fully matches a regex pattern.

Unlike contains_regex which searches for a match anywhere, this requires the entire string to match (anchored ^...$).

Source

pub fn fullmatch_with_options( &self, pat: &str, case: bool, na: Option<bool>, ) -> Result<Series, FrameError>

Fullmatch with case/na option parity.

Matches pd.Series.str.fullmatch(pat, case=True, na=None). case=false enables inline (?i) matching. na=None propagates nulls as NaN; na=Some(bool) replaces null entries with the chosen boolean.

Source

pub fn match_regex(&self, pat: &str) -> Result<Series, FrameError>

Check whether each string matches a regex pattern at the start.

Analogous to pandas.Series.str.match(pat) which uses Python’s re.match() (anchored at the beginning of the string).

Source

pub fn match(&self, pat: &str) -> Result<Series, FrameError>

Check whether each string matches a regex pattern at the start.

Rust raw-identifier spelling for pandas.Series.str.match(pat).

Source

pub fn match_regex_with_options( &self, pat: &str, case: bool, na: Option<bool>, ) -> Result<Series, FrameError>

Match (start-anchored) with case/na option parity.

Matches pd.Series.str.match(pat, case=True, na=None) — Python’s re.match semantics (anchored at start, not end). case=false enables inline (?i) matching; na handling mirrors fullmatch_with_options.

Source

pub fn split_regex_get(&self, pat: &str, n: i64) -> Result<Series, FrameError>

Split each string by a regex pattern and return the n-th element.

Analogous to pandas.Series.str.split(pat, regex=True).str[n].

Source

pub fn zfill(&self, width: usize) -> Result<Series, FrameError>

Zero-fill strings to specified width.

Matches pd.Series.str.zfill(width).

Source

pub fn center(&self, width: usize, fillchar: char) -> Result<Series, FrameError>

Center-align strings within specified width.

Matches pd.Series.str.center(width, fillchar).

Source

pub fn ljust(&self, width: usize, fillchar: char) -> Result<Series, FrameError>

Left-align strings within specified width (pad on right).

Matches pd.Series.str.ljust(width, fillchar).

Source

pub fn rjust(&self, width: usize, fillchar: char) -> Result<Series, FrameError>

Right-align strings within specified width (pad on left).

Matches pd.Series.str.rjust(width, fillchar).

Source

pub fn isdigit(&self) -> Result<Series, FrameError>

Check if each string is composed of digits only.

Matches pd.Series.str.isdigit().

Source

pub fn isalpha(&self) -> Result<Series, FrameError>

Check if each string is composed of alphabetic characters only.

Matches pd.Series.str.isalpha().

Source

pub fn isalnum(&self) -> Result<Series, FrameError>

Check if each string is alphanumeric.

Matches pd.Series.str.isalnum().

Source

pub fn isascii(&self) -> Result<Series, FrameError>

Check if each string is composed of ASCII characters only.

Matches pd.Series.str.isascii().

Source

pub fn isspace(&self) -> Result<Series, FrameError>

Check if each string is composed of whitespace only.

Matches pd.Series.str.isspace().

Source

pub fn islower(&self) -> Result<Series, FrameError>

Check if each string is lowercase.

Matches pd.Series.str.islower().

Source

pub fn isupper(&self) -> Result<Series, FrameError>

Check if each string is uppercase.

Matches pd.Series.str.isupper().

Source

pub fn isnumeric(&self) -> Result<Series, FrameError>

Check if each string is numeric (including Unicode numeric chars).

Matches pd.Series.str.isnumeric().

Source

pub fn get(&self, i: i64) -> Result<Series, FrameError>

Extract character at position from each string.

Matches pd.Series.str.get(i). Returns NaN if index is out of bounds.

Source

pub fn wrap(&self, width: usize) -> Result<Series, FrameError>

Wrap long lines at specified width.

Matches pd.Series.str.wrap(width). Inserts newlines to wrap text.

Source

pub fn wrap_with_drop_whitespace( &self, width: usize, drop_whitespace: bool, ) -> Result<Series, FrameError>

Wrap long lines while controlling whether boundary whitespace is dropped.

Matches pd.Series.str.wrap(width, drop_whitespace=...) for the supported strict-mode behavior covered by the conformance fixtures.

Source

pub fn normalize(&self, form: &str) -> Result<Series, FrameError>

Normalize Unicode strings.

Matches pd.Series.str.normalize(form) for NFC, NFKC, NFD, and NFKD.

Source

pub fn isdecimal(&self) -> Result<Series, FrameError>

Check if each string is a valid decimal number.

Matches pd.Series.str.isdecimal().

Source

pub fn istitle(&self) -> Result<Series, FrameError>

Check if each string is titlecased.

Matches pd.Series.str.istitle().

Source

pub fn cat(&self, sep: &str) -> Result<String, FrameError>

Return the string representation of each element.

Matches pd.Series.str.cat() - concatenate strings. Concatenates all strings in the Series with a separator.

Source

pub fn cat_series( &self, others: &Series, sep: &str, na_rep: Option<&str>, ) -> Result<Series, FrameError>

Concatenate strings element-wise with another Series.

Matches pd.Series.str.cat(others, sep, na_rep). na_rep is used to replace Null values in either Series.

Source

pub fn cat_list( &self, others: &[&Series], sep: &str, na_rep: Option<&str>, ) -> Result<Series, FrameError>

Concatenate strings element-wise with multiple other Series.

Matches pd.Series.str.cat([s1, s2, ...], sep, na_rep).

Source

pub fn find(&self, sub: &str) -> Result<Series, FrameError>

Find the first occurrence of a substring.

Matches pd.Series.str.find(sub). Returns -1 if not found. Per br-frankenpandas-02ae2b: pandas returns CHAR-based positions (Python 3 strings are char-indexed), not byte positions.

Source

pub fn rfind(&self, sub: &str) -> Result<Series, FrameError>

Find the last occurrence of a substring.

Matches pd.Series.str.rfind(sub). Returns -1 if not found. Per br-frankenpandas-02ae2b: char-based, not byte-based.

Source

pub fn find_with_bounds( &self, sub: &str, start: i64, end: Option<i64>, ) -> Result<Series, FrameError>

Find the first occurrence of a substring within s[start:end].

Matches pd.Series.str.find(sub, start, end) (Python str.find semantics): start/end are CHARACTER positions, negative values count from the end, and out-of-range values clamp to [0, len]. The returned index is the char position in the FULL string (not the slice), or -1.

Source

pub fn rfind_with_bounds( &self, sub: &str, start: i64, end: Option<i64>, ) -> Result<Series, FrameError>

Find the last occurrence of a substring within s[start:end].

Matches pd.Series.str.rfind(sub, start, end) (Python str.rfind). See find_with_bounds for the start/end rules.

Source

pub fn index(&self, sub: &str) -> Result<Series, FrameError>

Find the first occurrence of a substring; error if any non-null string misses it.

Matches pd.Series.str.index(sub).

Source

pub fn rindex(&self, sub: &str) -> Result<Series, FrameError>

Find the last occurrence of a substring; error if any non-null string misses it.

Matches pd.Series.str.rindex(sub).

Source

pub fn index_with_bounds( &self, sub: &str, start: i64, end: Option<i64>, ) -> Result<Series, FrameError>

Find the first occurrence of a substring within s[start:end]; error if not found. Matches pd.Series.str.index(sub, start, end) (Python str.index). See find_with_bounds for the start/end rules.

Source

pub fn rindex_with_bounds( &self, sub: &str, start: i64, end: Option<i64>, ) -> Result<Series, FrameError>

Find the last occurrence of a substring within s[start:end]; error if not found. Matches pd.Series.str.rindex(sub, start, end) (Python str.rindex).

Source

pub fn index_of(&self, sub: &str) -> Result<Series, FrameError>

Find the first occurrence of a substring; error if not found.

Matches pd.Series.str.index(sub). Like find() but raises an error for missing values (here, returns NaN for not-found). Per br-frankenpandas-02ae2b: char-based, not byte-based.

Source

pub fn rindex_of(&self, sub: &str) -> Result<Series, FrameError>

Find the last occurrence of a substring; error if not found.

Matches pd.Series.str.rindex(sub). Like rfind() but raises an error for missing values (here, returns NaN for not-found). Per br-frankenpandas-02ae2b: char-based, not byte-based.

Source

pub fn expandtabs(&self, tabsize: usize) -> Result<Series, FrameError>

Replace tab characters with spaces.

Matches pd.Series.str.expandtabs(tabsize).

Source

pub fn removeprefix(&self, prefix: &str) -> Result<Series, FrameError>

Remove a prefix from each string if present.

Matches pd.Series.str.removeprefix(prefix) (Python 3.9+ / pandas 1.4+).

Source

pub fn removesuffix(&self, suffix: &str) -> Result<Series, FrameError>

Remove a suffix from each string if present.

Matches pd.Series.str.removesuffix(suffix) (Python 3.9+ / pandas 1.4+).

Source

pub fn casefold(&self) -> Result<Series, FrameError>

Aggressive Unicode case folding.

Matches pd.Series.str.casefold(). Like lower() but more aggressive for Unicode (e.g., German sharp s).

Source

pub fn swapcase(&self) -> Result<Series, FrameError>

Swap the case of each character.

Matches pd.Series.str.swapcase().

Source

pub fn partition( &self, sep: &str, ) -> Result<(Series, Series, Series), FrameError>

Split each string at the first occurrence of separator.

Matches pd.Series.str.partition(sep). Returns a tuple-like string “(before, sep, after)” or “(original, ‘’, ‘’)” if sep not found. Returns three separate values as a comma-separated string for simplicity.

Source

pub fn rpartition( &self, sep: &str, ) -> Result<(Series, Series, Series), FrameError>

Split each string at the last occurrence of separator.

Matches pd.Series.str.rpartition(sep).

Source

pub fn partition_df(&self, sep: &str) -> Result<DataFrame, FrameError>

Split the string at the first occurrence of sep and return a DataFrame.

Matches pd.Series.str.partition(sep).

Source

pub fn rpartition_df(&self, sep: &str) -> Result<DataFrame, FrameError>

Split the string at the last occurrence of sep and return a DataFrame.

Matches pd.Series.str.rpartition(sep).

Source

pub fn get_dummies(&self, sep: &str) -> Result<DataFrame, FrameError>

Split each string by separator and return a DataFrame of indicator columns.

Matches pd.Series.str.get_dummies(sep). Each unique token becomes a column with 1/0 indicators.

Source

pub fn encode(&self, _encoding: &str) -> Result<Series, FrameError>

Encode strings to bytes (returns byte length as Float64).

Matches pd.Series.str.encode(encoding). Since Rust strings are always UTF-8, this returns the byte length of each string for the “utf-8” encoding. Per br-frankenpandas-rg8ys.6.6: pandas returns float64 for nullable integers (nulls become NaN).

Source

pub fn decode(&self, _encoding: &str) -> Result<Series, FrameError>

Decode bytes to strings (identity operation in Rust).

Matches pd.Series.str.decode(encoding). Since Rust strings are always UTF-8, this is an identity operation.

Source

pub fn translate(&self, from: &str, to: &str) -> Result<Series, FrameError>

Translate characters using a mapping table.

Matches pd.Series.str.translate(table). Replaces each character found in from with the corresponding character in to. If to is shorter than from, excess mapped characters are deleted.

Auto Trait Implementations§

§

impl<'a> Freeze for StringAccessor<'a>

§

impl<'a> RefUnwindSafe for StringAccessor<'a>

§

impl<'a> Send for StringAccessor<'a>

§

impl<'a> Sync for StringAccessor<'a>

§

impl<'a> Unpin for StringAccessor<'a>

§

impl<'a> UnsafeUnpin for StringAccessor<'a>

§

impl<'a> UnwindSafe for StringAccessor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.