过滤pandas数据框列中的字符串/浮点数/整数值 [英] Filtering string/float/integer values in pandas dataframe columns
本文介绍了过滤pandas数据框列中的字符串/浮点数/整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在如下所示的熊猫数据框中仅过滤一列( SIC
)中的字符串值/整数/浮点值?
How can I filter only string values/ integer/ float values in one column (SIC
) in a pandas data frame like below?
SIC
1 246804
2 135272
3 898.01
4 3453.33
5 shine
6 add
7 522
8 Nan
9 string
10 29.11
11 20
推荐答案
您可以使用 pd.to_numeric
和布尔索引的输出.
You can use the outputs from pd.to_numeric
and boolean indexing.
要仅获取字符串,请使用:
To get only the strings use:
df[pd.to_numeric(df.SIC, errors='coerce').isnull()]
输出:
SIC
5 shine
6 add
8 Nan
9 string
要仅获取数字,请使用:
To get only the numbers use:
df[pd.to_numeric(df.SIC, errors='coerce').notnull()]
输出:
SIC
1 246804
2 135272
3 898.01
4 3453.33
7 522
10 29.11
11 20
这篇关于过滤pandas数据框列中的字符串/浮点数/整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文