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

lxdthriller picture lxdthriller · Sep 2, 2016 · Viewed 43k times · Source

Taking the following example:

>>> 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')

The output is:

   y
a  3
b  4
c  5
d  6
e  7
b  1
c  3
d  5
e  7
f  9

Since axis=0 is the columns, I think tha concat() only considers columns that are found in both dataframes. But the acutal output considers rows that are found in both dataframes.

What is the exactly meaning of axis parameter?

Answer

debaonline4u picture debaonline4u · Sep 23, 2018

If someone needs visual description, here is the image:

Axis 0 or 1 in Pandas Python