3

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

sangeeth kumar
  • 319
  • 2
  • 7
  • 23

1 Answers1

6

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.
jpp
  • 159,742
  • 34
  • 281
  • 339