过滤列( pandas )中的字符串/浮点数/整数值 [英] Filtering string/float/interger values in columns (Pandas)
本文介绍了过滤列( pandas )中的字符串/浮点数/整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何仅过滤如下所示的pandas数据框中的一列中的字符串值/整数/浮点值?
How can I filter only string values / integer / float values in one column in 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.
仅获取字符串使用:
df[pd.to_numeric(df.SIC, errors='coerce').isnull()]
输出:
SIC
5 shine
6 add
8 Nan
9 string
获得仅数字使用:
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屋!
查看全文