I have a data frame that is constructed by pd.read_excel. I want to create a second data frame by selecting all rows of the prior data frame where a column of the excel has a empty cell.
Something like
A = df.loc[df["column"]==None]
did not work.
In order to check missing values in Pandas DataFrame, we use a function isnull() and notnull(). Both function help in checking whether a value is NaN or not. These function can also be used in Pandas Series in order to find null values in a series.
shape() method returns the number of rows and number of columns as a tuple, you can use this to check if pandas DataFrame is empty. DataFrame. shape[0] return number of rows. If you have no rows then it gives you 0 and comparing it with 0 gives you True .
df. dropna(subset=['B']) will do exactly that. subset here is used as a criteria. In other words, row is dropped if and only if cell of column B is empty: if row has an empty cell in column A , dropna(subset=['B']) will not drop anything.
Use isnull
instead
A = df.loc[df["column"].isnull()]
Alternatively, you could use query
because None
is not equal to itself, this works
A = df.query('column != column')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With