pandas - how to understand axis = 0 or 1 in Python -


from documentation, "the first running vertically downwards across rows (axis 0), , second running horizontally across columns (axis 1)" , code

df1 = pd.dataframe({"x":[1, 2, 3, 4, 5],                      "y":[3, 4, 5, 6, 7]},                     index=['a', 'b', 'c', 'd', 'e'])   df2 = pd.dataframe({"y":[1, 3, 5, 7, 9],                      "z":[9, 8, 7, 6, 5]},                     index=['b', 'c', 'd', 'e', 'f']) pd.concat([df1, df2], join='inner') # default axis=0 

since axis=0( interpret column) think concat considers columns found in both dataframes. acutal output considers rows found in both dataframes.(the common row element 'y') how should understand axis=0,1 correctly?

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

if apply general interpretation case, algorithm here concat. axis=0, means:

for each column, take rows down (across dataframes concat) , , contact them when in common (because selected join=inner).

so meaning take columns x , concat them down rows stack each chunk of rows 1 after another. however, here x not present everywhere, not kept final result. same applies z. y result kept y in dataframes. result have.


Comments