What is the meaning of “axis” attribute in a Pandas DataFrame?

前端 未结 5 1922
遇见更好的自我
遇见更好的自我 2021-02-04 02:28

Taking the following example:

>>> df1 = pd.DataFrame({\"x\":[1, 2, 3, 4, 5], 
                        \"y\":[3, 4, 5, 6, 7]}, 
                      ind         


        
5条回答
  •  难免孤独
    2021-02-04 03:22

    This is my trick with axis: just add the operation in your mind to make it sound clear:

    • axis 0 = rows
    • axis 1 = columns

    If you “sum” through axis=0, you are summing all rows, and the output will be a single row with the same number of columns. If you “sum” through axis=1, you are summing all columns, and the output will be a single column with the same number of rows.

提交回复
热议问题