I'm playing around with pandas and I'm trying to get some NaN columns to be filled in with 0(and leaving others untouched).
Here's what I'm trying:
variablesToCovertToZero = ['column1', 'column2'] #just a list of columns
print('before ', df.isna().sum().sum()) #show me how many nulls
# df = df.update(df[variablesToCovertToZero].fillna(0, inplace=True)) #try 1, didn't work
df[variablesToCovertToZero].fillna(0, inplace=True) #try 2, also didn't work
print('after ', df.isna().sum().sum())
Results when I run it:
before 11056930
/opt/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py:4259: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
**kwargs
after 11056930
the before and after are the same! But I am also getting a warning. In the past the warning wasn't a problem but I thought I'd add it in just in case it was related.
Any suggestions on what I'm doing wrong? I just want to use the fillin option for specific list of columns.