Search code examples
pythonnanonetype

Removing N/A from table in Python with none - 'NoneType' object has no attribute 'where'


I have a table in python with multiple columns with N/A and i want to replace those with None or blank if possible. I have tried many ways but i got all the time this message :

'NoneType' object has no attribute 'where'

I have tried this :

 main = main_df.where(pd.notnull(df), None)
 print(main) 

and also tried this :

 main = main_df.fillna('', inplace=True)

and this :

main = main_df.replace(np.nan, '', regex=True)
print(main)

Whatever i am trying the messege is the same : 'NoneType' object has no attribute 'where' or 'replace'

Do you have any idea how should i do that ? I am desperate to fix this . Appreciate all the help ! Thanks a lot !


Solution

  • The problem is not caused here - the error you're given, means that the value of main_df is None.

    The easiest way to detect what is causing the problem is to use print(main_df) whenever it's changed (including the line where it's first declared), and see where it starts to be None