You are viewing documentation about an older version (1.21.0). View latest version

modin.pandas.Series.str.split¶

Series.str.split(pat=None, *, n=- 1, expand=False, regex=None)[source]¶

Split strings around given separator/delimiter.

Splits the string in the Series/Index from the beginning, at the specified delimiter string.

Parameters:
  • pat (str, optional) – String to split on. If not specified, split on whitespace.

  • n (int, default -1 (all)) – Limit number of splits in output. None, 0 and -1 will be interpreted as return all splits.

  • expand (bool, default False (Not implemented yet, should be set to False)) – Expand the split strings into separate columns. - If True, return DataFrame/MultiIndex expanding dimensionality. - If False, return Series/Index, containing lists of strings.

  • regex (bool, default None (Not implemented yet, should be set to False or None)) – Determines if the passed-in pattern is a regular expression: - If True, assumes the passed-in pattern is a regular expression - If False or None, treats the pattern as a literal string.

Returns:

Type matches caller unless expand=True (see Notes).

Return type:

Series, Index, DataFrame or MultiIndex

See also

Series.str.split

Split strings around given separator/delimiter.

Series.str.rsplit

Splits string around given separator/delimiter, starting from the right.

Series.str.join

Join lists contained as elements in the Series/Index with passed delimiter.

str.split

Standard library version for split.

str.rsplit

Standard library version for rsplit.

Notes

The handling of the n keyword depends on the number of found splits:

  • If found splits > n, make first n splits only

  • If found splits <= n, make all splits

  • If for a certain row the number of found splits < n, append None for padding up to n if expand=True

  • If using expand=True, Series and Index callers return DataFrame and MultiIndex objects, respectively.

Examples

>>> s = pd.Series(
...     [
...         "this is a regular sentence",
...         "https://docs.python.org/3/tutorial/index.html",
...         np.nan
...     ]
... )
>>> s
0                       this is a regular sentence
1    https://docs.python.org/3/tutorial/index.html
2                                             None
dtype: object
Copy

In the default setting, the string is split by whitespace.

>>> s.str.split()
0                   [this, is, a, regular, sentence]
1    [https://docs.python.org/3/tutorial/index.html]
2                                               None
dtype: object
Copy

The n parameter can be used to limit the number of splits on the delimiter.

>>> s.str.split(n=2)
0                     [this, is, a regular sentence]
1    [https://docs.python.org/3/tutorial/index.html]
2                                               None
dtype: object
Copy

The pat parameter can be used to split by other characters.

>>> s.str.split(pat="/")
0                         [this is a regular sentence]
1    [https:, , docs.python.org, 3, tutorial, index...
2                                                 None
dtype: object
Copy