简体   繁体   English

如何删除df中整个列的某个字符后的所有内容?

[英]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:这是该列的示例:

SKUID

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.

相关问题 如何删除字符串中某个字符后的所有内容? - How to delete everything after a certain character in a string? 删除所有内容,直到python中的某些字符串或字符 - Delete everything until certain string or character in python 如何删除某个字符后的所有内容? - How do I remove everything after a certain character? 如何在某个字符之后删除列表中的字符? - How to delete characters in a list after a certain character? Pandas 系列:删除某个字符之前的所有内容,如果“所有内容”每次都更改 - Pandas series: Delete everything before a certain character, if "everything" changes everytime 熊猫-在字符串列中某个字符之后“剪切”所有内容并将其粘贴到列的开头 - Pandas - 'cut' everything after a certain character in a string column and paste it in the beginning of the column 删除特定字符后的所有字符,而不是字符本身,在整列中,python - delete all characters after specific character, not character itself, in whole column, python 我如何在数据框中的整个列中将 df['2'] 除以 df['1'] ? - how I divide df['2'] by df['1'] throughout a whole column in a dataframe? 如何删除 Python 中某个字符之前的所有内容 - How to remove everything before certain character in Python 如何删除 python 中 pandas df 列中某个字符之前的所有字符 - How to remove all characters before a certain character in pandas df column in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM