I'm running Pandas in Python 3 and I noticed that the following:
import pandas as pd
import numpy as np
from pandas import DataFrame
from numpy import nan
df = DataFrame([[1, nan], [nan, 4], [5, 6]])
print(df)
df2 = df
df2.fillna(0)
print(df2)
Returns the following:
0 1
0 1 NaN
1 NaN 4
2 5 6
0 1
0 1 NaN
1 NaN 4
2 5 6
While the following:
import pandas as pd
import numpy as np
from pandas import Series
from numpy import nan
sr1 = Series([1,2,3,nan,5,6,7])
sr1.fillna(0)
Returns the following:
0 1
1 2
2 3
3 0
4 5
5 6
6 7
dtype: float64
So it's filling in Series values but not DataFrame values with 0 when I use .fillna(). What am I missing here to get 0s in place of null values in DataFrames?