Deleting DataFrame row in Pandas based on column value Deleting DataFrame row in Pandas based on column value python python

Deleting DataFrame row in Pandas based on column value


If I'm understanding correctly, it should be as simple as:

df = df[df.line_race != 0]


But for any future bypassers you could mention that df = df[df.line_race != 0] doesn't do anything when trying to filter for None/missing values.

Does work:

df = df[df.line_race != 0]

Doesn't do anything:

df = df[df.line_race != None]

Does work:

df = df[df.line_race.notnull()]


just to add another solution, particularly useful if you are using the new pandas assessors, other solutions will replace the original pandas and lose the assessors

df.drop(df.loc[df['line_race']==0].index, inplace=True)