且构网

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

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

更新时间:2023-02-05 10:17:11

找到要删除的行,使用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)