Examples
import numpy as np
import pandas as pd
s = pd.Series(["this is my new pen",
"https://www.w3resource.com/pandas/index.php",
np.nan])
In the default setting, the string is split by whitespace.
s.str.split()
Without the n parameter, the outputs of rsplit and split are identical.
The n parameter can be used to limit the number of splits on the delimiter. The outputs of split and
rsplit are different.
s.str.split(n=2)
The pat parameter can be used to split by other characters.
s.str.split(pat = "/")
When using expand=True, the split elements will expand out into separate columns. If NaN is present,
it is propagated throughout the columns during the split.
s.str.split(expand=True)
Remember to escape special characters when explicitly using regular expressions.
s = pd.Series(["1+1=2"])
s.str.split(r"\+|=", expand=True)