Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the row and column for empty cell using pandas

I am trying to fetch xls file which contains empty cells. I need to validate the xls file using pandas to get row and column position

This is the excel sheet

Expected output:

The row 2, col 2 has empty value [OR] Tenant ID is not found for Account1

like image 990
sangeeth kumar Avatar asked Sep 20 '25 14:09

sangeeth kumar


1 Answers

Try this to obtain a list of Account Names with no Tenant Id:

res = df.loc[df['Tenant ID'].isnull(), 'Account Name'].tolist()

Alternatively, to filter your dataframe for rows where Tenant Id is empty:

df = df.loc[df['Tenant ID'].isnull(), :]

Explanation

  • .loc accessor lets you specify row and column by Boolean arrays or label.
  • For row filter, we use a Boolean array via pd.Series.isnull to identify rows where Tenant Id is blank.
  • For column filter, we can use 'Account Name' and output to list via pd.Series.tolist.
like image 150
jpp Avatar answered Sep 22 '25 02:09

jpp