Pandas 根据值删除数据框中的一行 [英] Pandas delete a row in a dataframe based on a value
本文介绍了Pandas 根据值删除数据框中的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除第二列 = 0 的 Pandas 数据框中的行
I want do delete rows in a pandas dataframe where a the second column = 0
所以这个...
Code Int
0 A 0
1 A 1
2 B 1
会变成这样...
Code Int
0 A 1
1 B 1
非常感谢任何帮助!
推荐答案
找到要删除的行,使用drop.
Find the row you want to delete, and use drop.
delete_row = df[df["Int"]==0].index
df = df.drop(delete_row)
print(df)
Code Int
1 A 1
2 B 1
更多.您可以使用 iloc 来查找行,如果你知道列的位置
Further more. you can use iloc to find the row, if you know the position of the column
delete_row = df[df.iloc[:,1]==0].index
df = df.drop(delete_row)
这篇关于Pandas 根据值删除数据框中的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文