0

I have to retreat a dataframe's column where all observations contain the same type of value, a string as follows :

'Total: 1'
'Total: 1'
'Total: 2'
etc.

Then I try to run the apply method like this to the column evolLevel which contains those strings :

df['evolLevel'].apply(lambda x: x[-1])

However it returns me the following error although this is still a string variable :

'float' object is not subscriptable

I've also tried to specify axis=1 but it doesn't change anything.

GaëtanLF
  • 101
  • 10

1 Answers1

1

To whom it may be interesting, it finally worked when I did :

df['evolLevel'] = df['evolLevel'].apply(lambda x: str(x)[-1])
GaëtanLF
  • 101
  • 10