我在 pandas 中有一列混合了字符串和数字 我想从字符串中去除数字。
A
11286011
11268163
C7DDA72897
C8ABC557
Abul
C80DAS577
C80DSS665
想要输出为
A
C7DDA72897
C8ABC557
Abul
C80DAS577
C80DSS665
最佳答案
In [52]: df
Out[52]:
A
0 11286011
1 11268163
2 C7DDA72897
3 C8ABC557
4 C80DAS577
5 C80DSS665
In [53]: df = pd.to_numeric(df.A, errors='coerce').dropna()
In [54]: df
Out[54]:
0 11286011.0
1 11268163.0
Name: A, dtype: float64
或使用正则表达式:
In [59]: df.loc[~df.A.str.contains(r'\D+')]
Out[59]:
A
0 11286011
1 11268163
关于python-2.7 - Pandas 从 python 中的字符串列中删除数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43393559/