我有一个数据帧:
游泳(4) 14远足(1) 2运行(12) 3.5钓鱼(2)
| | sid | Hobby (times per month) |
|-----+-------+-------------------------|
| 0 | 3 | swimming(4) |
|-----+-------+-------------------------|
| 1 | 4 | hiking (1 ) |
|-----+-------+-------------------------|
| 2 | 2 | running ( 12 ) |
|-----+-------+-------------------------|
| 3 | 5 | fishing ( 2 ) |
如何通过删除第二列中的括号来提取字符串,如下所示:
| | sid | Hobby (times per month) |
|-----+-------+-------------------------|
| 0 | 3 | swimming |
|-----+-------+-------------------------|
| 1 | 4 | hiking |
|-----+-------+-------------------------|
| 2 | 2 | running |
|-----+-------+-------------------------|
| 3 | 5 | fishing |
要在pandas中实现regex,可以使用熊猫。应用():
例如,如果希望将
swimming(4)
更改为swimming
,可以使用下面的正则表达式:演示:https://regex101.com/r/sTO1Q9/1
测试用例:
匹配:
您可以使用'str'方法来匹配pandas中的字符串
相关问题 更多 >
编程相关推荐