I'm trying to use Series.str.rsplit
to return everything up to the delimiter, but can't seem to get past this TypeError I'm receiving:
TypeError: StringMethods.rsplit() takes from 1 to 2 positional arguments but 3 were given
I am using pandas 2.0.3
. Here is my code:
import pandas as pd
df1 = pd.DataFrame({'name': ['tom ent', 'nick', 'krish std', 'jack whatever'],
'age': ['5', '6', '7', '8']})
df1['name'] = df1['name'].str.rsplit(' ', 1).str[0]
Output should look like:
name age
tom 5
nick 6
krish 7
jack 8
Not sure what I'm missing here.