I am trying to simply skip over a record that is found within my relevant excel file as: empty, blank, or 'N/A'. I want the script to continue or skip; not stop if a record is found empty, N/A.
I am trying the below, but the script is still stopping at a blank, or N/A found record in the excel file....
for row in excel_data.itertuples():
mrn = row.MRN
if mrn in ("", " ", "N/A", None) or math.isnan(mrn):
print(f"Invalid record: {row}")
excel_data = excel_data.drop(excel_data.index[row.Index])
else:
num_valid_records += 1
print(f"Processing #{num_valid_records} records")
More context:
I'm importing data from an excel file, to pandas, to a web page (web form).
- I noticed the excel file has a few cells with values as 'N/A'.
- In the pandas data frame a few values are also outputting as 'NaT'.
- Currently as is my script is stopping when excepting a Date record from a cell, but instead this cell contains a 'N/A'. This entry is not required, so I just want it to skip if N/A is found, instead of stopping.
- I want it to simply skip this problem cell (i.e. found blank, or within N/A') and continue with the other records.