Pandas axis=0 and axis=1
Just as in the image, some times we want to say whether we should put x first or y first, for Numpy, we want to know which axis should be the row and which axis should be column.
A nice discussion can be found in [1].
The top answer from [1] is pretty clear.
It specifies the axis along which the means are computed. By default
axis=0
. This is consistent with thenumpy.mean
usage whenaxis
is specified explicitly (innumpy.mean
, axis==None by default, which computes the mean value over the flattened array) , in whichaxis=0
along the rows (namely, index in pandas), andaxis=1
along the columns. For added clarity, one may choose to specifyaxis='index'
(instead ofaxis=0
) oraxis='columns'
(instead ofaxis=1
). Top answer from [1]
along which is critical. As the pandas is putting the same type data to each column, so column should has a higher priority, this is the missing point I want to highlight from the top answer.
Reference
[1] https://stackoverflow.com/questions/22149584/what-does-axis-in-pandas-mean