2024-10-04 11:24:36 发布
网友
我正在寻找一种有效的方法来删除数据帧列中字符串中不需要的部分。你知道吗
例如,我要删除的字符串是0x0469,还有许多其他字符串都以“0x”开头。如何删除所有以“0x”开头的字符串并将其替换为0
部分数据帧示例
Index Totbytes Dur 0 500 30.11344 1 262 0x00469 2 345 45.33333
既然你要求regex:
regex
s = df['Dur'].str.match('^(0x).*')
其中^表示字符串的开头,表示:
^
0 False 1 True 2 False Name: Dur, dtype: bool
所以:
df[~s]
给你:
Index Totbytes Dur 0 0 500 30.11344 2 2 345 45.33333
既然你要求
regex
:其中
^
表示字符串的开头,表示:所以:
给你:
相关问题 更多 >
编程相关推荐