[英]How to delete everything after a certain character for whole column in df?
I have a df with one column (SKUID) where I want to remove all the characters that are not numerical.我有一个带有一列 (SKUID) 的 df,我想在其中删除所有非数字字符。 Here is an sample of the column:
这是该列的示例:
Essentially I want to remove the underscore and the letter for each row.基本上我想删除每一行的下划线和字母。 I have tried using following code:
我尝试使用以下代码:
sku_data.split('_', 1)[0]
This gives me an error of 'DataFrame' object has no attribute 'split'.这给了我“DataFrame”对象没有属性“split”的错误。 Where am I going wrong?
我哪里错了?
This should do for number extraction:这应该用于数字提取:
sku_data.SKUID = sku_data.SKUID.str.extract('(\d+)')
Note : don't forget to add the str
operator if you want to perform string operations on a DataFrame
column注意:如果要对
DataFrame
列执行字符串操作,请不要忘记添加str
运算符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.