canigan
canigan

Reputation: 29

Why is the output of my loc() function still showing the values I'm trying to filter out?

I have a dataframe with a whole lotta rows and 21 columns. I'm using this code to filter out the rows with blank values in the 'date' column.

master = pd.read_excel('master.xlsx')
master.loc[master['date'] != 'NaN']

I use 'NaN because that's what the values show up as when I print the master object. However, they are written as "NA" in the Excel document I sourced the info from. Even replacing 'NaN' with 'NA' still outputs a dataframe with the rows I am trying to exclude. Even replacing 'NaN' and 'NA' with '' still outputs the rows I am trying to exclude.

Upvotes: 0

Views: 75

Answers (1)

A.B
A.B

Reputation: 20445

you can use pandas builtin function to filter not nan values in df , for example with notnull()

master = master[master['date'].notnull()]

Upvotes: 2

Related Questions