I have a dataframe with a column Fib, I am trying to grab a substring from it:
Could anyone please tell me why this code does not work:
df['new'] = df['Fib'].apply(lambda x:x.str[2:10])
AttributeError: 'str' object has no attribute 'str'
But if i do this, it will work:
df['new_col'] = df['Fib'].astype(str).str[2:10]
I am trying to solve the above problem with apply+lambda just to get some experience with it. Thank you
df['new'] = df['Fib'].apply(lambda x:x[2:10])don't usestrinside the lambdaapply. Use slice instead