I am creating a pandas dataframe as follows:
data = {'A': [1, 2, None, 4], 'B': [1, 2, None, 4]}
x = pd.DataFrame(data)
A B
0 1.0 1.0
1 2.0 2.0
2 NaN NaN
3 4.0 4.0
Now, I aggregate across columns as:
x.agg("sum", axis='columns')
This results in:
0 2.0
1 4.0
2 0.0
3 8.0
dtype: float64
In this case, it seems to be treating NaN as 0 which is not what I want. Is it possible to treat missing values as NaNs for the aggregation i.e. the sum be NaN for such cases?