删除熊猫字符串类型系列中所有非数字字符

问题描述 投票:0回答:1

从下面的系列中,我要删除所有不是数字的字符,

   numbers
0   0312861
1   00
2   66065
3   6-0io09in4
4   .314
5   3194890809
6   :"<>":
7   3456.85
8   3465.22
9   312.724
10  300.363

为此,我尝试了代码:

df['numbers'] = df['numbers'].str.replace('\D', '', regex=True)
python regex pandas str-replace
1个回答
0
投票

您尝试改用apply吗?

© www.soinside.com 2019 - 2024. All rights reserved.