【发布时间】:2020-09-09 13:02:07
【问题描述】:
使用 python 使用正则表达式删除数据框列中特定值之前的值 有一个带有值的df:
df1
a b
tom score:abc132
luke score:123
mark score:132
mark score:132
luke value:123
tom value:145
luke score:123
tom marrks:145
如何使用正则表达式删除所有 b 列中 : 之前的值。
预期输出:
a b
tom abc132
luke 123
mark 132
mark 132
luke 123
tom 145
luke 123
tom 145
【问题讨论】:
-
为什么不使用
str.split?df['b'].str.split(':',expand=True)[1]
标签: python python-3.x regex pandas dataframe