I am doing the below, currently; successfully dropping the entire row, with my if in
- but it turns out, i don't need to drop the entire row.. How can I handle cells specifically.
How could I keep the same logic but apply to the CELL... convert the N/A,
NaT
, and NaN
cells to blank?
for row in excel_data.itertuples():
ids = row.IDS
total_records += 1
if ids in ("", " ", "N/A", "NaT", "NaN", None) or math.isnan(ids):
# print(f"Invalid record: {row}")
num_invalid_records += 1
# total_invalid = num_invalid_records + dup_count
excel_data = excel_data.drop(excel_data.index[row.Index])
# continue
else:
num_valid_records += 1
continue
My data looks like this: (below) As you can see there are N/As that seem to translate as 'NaTs' or Nan's in Pandas - I would just like to convert these to blank or " " or even skip somehow if possible....
In pandas the dataframe will output like this (i omitted some sensitive entries, but you get the idea).
External_Referral='qweryt', Transitions_Planning='NF', Date_ICP_ICT_Signed_by_Member__Caregiver=datetime.date(2019, 1, 10), Date_Refused_Final_Signature_of_ICP=datetime.date(2019, 1, 10), Refused_Final_Signature_Comments='concern', Intervention_Outcome='Successful Contact', Monthly_Member_Contact_Y_N='Yes', Monthly_Member_Contact_Date=datetime.date(2019, 1, 10), Special_Projects_HHB_program='Baby Box Given', ICT_Meeting_Dates_Additional_Comments=NaT, _20='Yes', Date=datetime.date(2019, 2, 12), Targeted_Case_Management_Referral='Yes')