[英]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.我有一个数据集,其中有一列用于客户 ID,另一列用于年龄,但是当我通过 pandas 上传数据时,它会自动开始索引年龄列。 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
:假设您只需要最后一个值,可以使用
apply
来实现:
df["Age"].apply(lambda x: x.split(",")[-1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.