简体   繁体   中英

How do I remove a part of a string from an entire column, if I want to remove all the values before a “,”?

This is my first time asking a question here, so apologizes if the formatting is off.

I have a dataset that has a column for a client ID and another one for the age, but when I uploaded the data through pandas, it automatically started indexing the age column. I would like to get rid of the additional numbers before the actual age.

Here's how it turned out:

Age : Client ID
1,56   A134
2,61   A35
3,34   B56
4,54   B74

And here's how I want it to look:

Age : Client ID
56    A134
61    A35
34    B56
54    B74

Thanks!

Assuming, you need only the last values, it can be achieved with apply :

df["Age"].apply(lambda x: x.split(",")[-1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM