且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

过滤列( pandas )中的字符串/浮点数/整数值

更新时间:2023-11-28 18:51:46

您可以使用 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