Reputation: 59
I want to retreive the value from a dataframe column "age" data type as "Object". Age is in frequency for e.g, 10-20, 20-30.
I want to keep the upper end of the range.for e.g 20,30 etc.
I tried below logic:
df['age'] = df['age'].astype(str)
df['age'] = df['age'].str[1:].str.split('-', expand = True)[0]
df['age'] = df['age'].astype(int)
But getting the error as
"TypeError: 'StringMethods' object is not subscriptable"
What am I doing wrong?
Upvotes: 0
Views: 2165