Python - Pandas 删除带有字符串的行 [英] Python - Pandas Drop Rows with strings
本文介绍了Python - Pandas 删除带有字符串的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的数据集中,我有几行包含字符.我只需要包含所有整数的行.什么是最好的方法来做到这一点?下面的数据集:例如,我想删除第 2 行和第 3 行,因为它们分别包含 051A、04A 和 08B.
In my dataset, I have a few rows which contain characters. I only need rows which contain all integers. What is the best possible way to do this? Below data set: e.g I want to remove the rows 2nd and 3rd as they contain 051A, 04A, and 08B respectively.
1 2017 0 321 3 20 42 18
2 051A 0 321 3 5 69 04A
3 460 0 1633 16 38 17 08B
4 1811 0 822 8 13 65 18
推荐答案
不确定这里是否可以避免申请
Not sure if apply can be avoided here
df.apply(lambda x: pd.to_numeric(x, errors = 'coerce')).dropna()
0 1 2 3 4 5 6 7
0 1 2017.0 0 321 3 20 42 18.0
3 4 1811.0 0 822 8 13 65 18.0
这篇关于Python - Pandas 删除带有字符串的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文