Pandas 根据值删除数据框中的一行

pmi*_*rhk 3 python pandas

我想删除第二列 = 0 的 Pandas 数据框中的行

所以这 ...

  Code  Int
0    A    0
1    A    1
2    B    1
Run Code Online (Sandbox Code Playgroud)

会变成这样...

  Code  Int
0    A    1
1    B    1
Run Code Online (Sandbox Code Playgroud)

非常感谢任何帮助!

Hsg*_*gao 10

找到要删除的行,然后使用drop

delete_row = df[df["Int"]==0].index
df = df.drop(delete_row)
print(df)
Code    Int
1   A   1
2   B   1
Run Code Online (Sandbox Code Playgroud)

此外。如果您知道列的位置,则可以使用iloc查找行

delete_row = df[df.iloc[:,1]==0].index
df = df.drop(delete_row)
Run Code Online (Sandbox Code Playgroud)