Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas data frame read_excel: How to look for empty cells?

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.

like image 398
nvrslnc Avatar asked Jan 25 '17 07:01

nvrslnc


People also ask

How do you find empty cells in a DataFrame?

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.

How do you check if a cell is empty in Pandas?

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 .

How will you identify empty cells in an excel sheet file using Pandas?

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.


1 Answers

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')
like image 135
piRSquared Avatar answered Oct 14 '22 17:10

piRSquared