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

Question:

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 !

Asked By: Georgiana Pislaru

||

Answers:

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

Answered By: BlackAnubis7

If you read the error message, it tells you that main_df, which is of type NoneType does not have where attribute.
This is probably because you have done something like this:

main_df = main_df.some_function(inplace=True)

See, pandas methods with inplace=True don’t return anything. Just remove this argument and it should work

Answered By: qmeeus
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.