Could anyone explain why pandas doesn't sum across both axes with parameter axis=None. As it said in API reference:
pandas.DataFrame.sum
DataFrame.sum(axis=None, skipna=True, numeric_only=False, min_count=0, **kwargs)
This is equivalent to the method numpy.sum
Parameters: axis: {index (0), columns (1)}
Axis for the function to be applied on. For Series this parameter is unused and defaults to 0.
For DataFrames, specifying axis=None will apply the aggregation across both axes.
But when I use parameter axis=None it works the same as axis=0
import pandas as pd
df = pd.DataFrame({'a':[1,2,3], 'b':[4,6,8]})
df
Output:
a b
0 1 4
1 2 6
2 3 8
df.sum(axis=None)
Output:
a 6
b 18
dtype: int64
The same as:
df.sum(axis=0)
Output:
a 6
b 18
dtype: int64
Shouldn't it work as numpy.sum() works?
import numpy as np
df.to_numpy().sum()
Output:
24