I am getting the following output, in my pandas dataframe; seemingly because of my seldom null
values for certain records:
Cannot convert non-finite values (NA or inf) to integer
How can I write a handler or something in python/pandas to convert my seldom N/A
record values to 0 - when they are appearing, so my script can continue; for presumably a fix to this?
Below is my code; with attempt of usage of fillna()
- this code addition removes the 'Cannot convert non-finite values..' error in dataframe output.
However it still displays the NaT
in the pandas data frame output for those seldom records.
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])
excel_data = excel_data.fillna(0) # attempt
continue
else:
num_valid_records += 1
print(f"Processing #{num_valid_records} records")
return self.clean_data_frame(excel_data)