python-2.7 - Pandas 从 python 中的字符串列中删除数字

标签 python-2.7 python-3.x pandas

我在 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/

相关文章:

Pandas : How to get timestamp. 天和 timestamp.month 填充零

python - 在 Pandas 系列中制作缺失的时隙并填充 0 值

python - 在 Python 中迭代 URL 列表 - bs4

python - 在 Sublime Text 2 中运行 python 出现错误

python - ap.add_argument()的语法

python - f-strings 应该在 Python 3.4 中工作吗?

python - 基于多个条件对多维数组进行排序的算法

python:如何将文件输出重定向到流

python - 能够实例化 python 类,尽管它是抽象的(使用 abc)

python - 为什么 pandas apply lambda 比这里的循环慢?