【发布时间】:2019-01-02 03:53:45
【问题描述】:
我有以下数据框列
>>> df2['Age]
1 25
2 35
3 48 y
4 34 yea
5 29
...
我只想保留数字并像那样替换 df2['Age] 中的值
1 25
2 35
3 48
4 34
5 29
...
我的代码不起作用:
df2.Age.replace('^.*','^[0-9]*[0-9]',regex=True,inplace=True)
这是结果
1 ^[0-9]*[0-9]
2 ^[0-9]*[0-9]
3 ^[0-9]*[0-9]
4 ^[0-9]*[0-9]
5 ^[0-9]*[0-9]
...
提前感谢您的帮助
【问题讨论】:
标签: python regex python-3.x dataframe