Can't Replace 0 to Nan in Python Using Pandas [Duplicate]
I Have Dataframe with Only 1 Column. I Want to Replace All '0' to Np. Nan but I Can't Achieve That. Dataframe Is Called Area. I Tried: Area. Replace(0, Np...
I have dataframe with only 1 column. I want to replace all '0' to np.nan but I can't achieve that.
dataframe is called area. I tried:
area.replace(0,np.nan)
area.replace(to_replace=0,np.nan)
area.replace(to_replace=0,value=np.nan)
area.replace('0',np.nan)
What should I do?
2 Answers
You can set inplace to True (default is False):
area.replace(0, np.nan, inplace=True)
See examples in docs.
You need to do:
area = area.replace(0, np.nan)