0

I am processing excel sheet with Pandas and checking if cells of each row with diff conditions. I am doing this by if and else for each cell. Is there any effective way to achieve this. Have some 30+ columns with diff checks to be processed. (few for dates, Nan, and others)

   if pd.isnull(col[4]):
      col[4] = 'NA'
   else:
      col[4] = datetime.strftime(col[4], '%m-%d')  
Andrew
  • 183
  • 2
  • 14
  • 1
    Please provide a [Provide a Minimal, Reproducible Example (e.g. code, data, errors) as text](https://stackoverflow.com/help/minimal-reproducible-example). Please [create a reproducible copy of the DataFrame with `df.head(10).to_clipboard(sep=',')`](https://stackoverflow.com/questions/52413246/how-to-provide-a-copy-of-your-dataframe-with-to-clipboard), [edit] the question, and paste the clipboard into a code block or include synthetic data: [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Trenton McKinney Jul 14 '20 at 04:17

1 Answers1

0

Not exactly what conditions you're using, but for nulls, you can definitely try

df.fillna("insert replacement") or in your case,it would be df.fillna('NA')

for a single column, use:

df['DataFrame Column'] = df['DataFrame Column'].fillna(0)

I can try to help further if you clarify what conditions you're trying to do.

Rayan Ral
  • 1,862
  • 2
  • 17
  • 17
  • Thanks. I have close to 30+ columns and after check all have to inserted to Oracle DB. Check are - date compatible (7-8 cols), NaN checks, special strings with in cells and mark some values based on other cols in the row. My question is how can I do this efficiently. Do you think, replacing each col (df['column-name']) before for loop will be efficient ? or any other way ? – Andrew Jul 14 '20 at 04:14