Say I have a column foo in a dataframe df, which looks like:
0 abc1
1 def
2 g3sse1
3 f32asd
I do not want the number at the end, if there is any.
0 abc
1 def
2 g3sse
3 f32asd
Like this.
The best I can do is:
df.foo[df['foo'].str[-1].str.isdigit()] = df['foo'].str[:-1]
This solves the problem, but... I am curious if there is more elegant way to do this. I guess regex won't make it look any better, but I appreciate any ideas!