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

前端 未结 5 1925
遇见更好的自我
遇见更好的自我 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:24

    Interpret axis=0 to apply the algorithm down each column, or to the row labels (the index).. A more detailed schema here.

    If you apply that general interpretation to your case, the algorithm here is concat. Thus for axis=0, it means:

    for each column, take all the rows down (across all the dataframes for concat) , and do contact them when they are in common (because you selected join=inner).

    So the meaning would be to take all columns x and concat them down the rows which would stack each chunk of rows one after another. However, here x is not present everywhere, so it is not kept for the final result. The same applies for z. For y the result is kept as y is in all dataframes. This is the result you have.

提交回复
热议问题