python: remove all rows in pandas dataframe that contain a string

后端 未结 2 2040
野趣味
野趣味 2021-02-07 13:52

I\'ve got a pandas dataframe called data and I want to remove all rows that contain a string in any column. For example, below we see the \'gdp\' column has a string at index 3,

2条回答
  •  太阳男子
    2021-02-07 14:15

    You can take the transpose, call ```convert_objects``, which works columns-wise, and then compare the data types to get a boolean key like this:

    df[df.T.convert_objects().dtypes != object]
    

提交回复
热议问题