Transfer: http://blog.csdn.net/wangying19911991/article/details/73928172
https://www.zhihu.com/question/58993137
The axis python exactly how to define it? Whether they are DataFrame on behalf of the rows or columns? Consider the following code:
>>>df = pd.DataFrame([[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], \
columns=["col1", "col2", "col3", "col4"])
>>>df
col1 col2 col3 col4
0 1 1 1 1
1 2 2 2 2
2 3 3 3 3
If we call df.mean (axis = 1), we get the mean calculated by row
>>> df.mean(axis=1)
0 1
1 2
2 3
However, if we call df.drop ((name, axis = 1), we actually deleted one, instead of one:
>>> df.drop("col4", axis=1)
col1 col2 col3
0 1 1 1
1 2 2 2
2 3 3 3
Someone help me understand what the true meaning of the pandas, numpy, scipy Among the three axis parameters do?
Voting highest answer reveals the nature of the problem:
Actually, the problem is understood axis have a problem, df.mean in fact, it is to take the average of all the columns on each line, instead of leaving the mean of each column. Perhaps the simplest is to remember axis = 0 interbank Representative (Down) , the axis = 1 Representative across columns (across) , as a method of operation of the adverb (Translator's Note)
in other words:
- Performed using the value of 0 indicates downward along each column or row label \ index value method
- 1 represents a value used along each row or column of the corresponding label template to perform a method
FIG DataFrame which represents the axis of representing meanings of 0 and 1:
the axis used to define more than one-dimensional array of properties, the two-dimensional data with two axes: the axis 0 along the vertical line downward, the first 1 along an axis extending in the horizontal row direction.
Therefore, a first problem which Liezi df.mean (axis = 1) represents the calculated mean horizontal direction along the column, while the second Liezi df.drop (name, axis = 1) representative of the name tag corresponding to the column (s) in the horizontal direction sequentially deleted.