Axis usage examples

In the axis usage examples, we calculate the mean for the values in the dataset. We have passed axis as 0. This means that the mean will be calculated along the row axis, as follows:

data.mean(axis=0) 

The following is the output:

Next, we set axis to 1. We are using the exact same method on the same dataset; however, we are changing axis from 0 to 1. Since we set axis to 1, the mean has been calculated along the columns:

data.mean(axis=1).head() 

The following is the output:

Sometimes it's difficult to remember whether 0 or 1 is for rows or columns. So instead of using axis0, you can set axis to rows:

data.mean(axis='rows') 

The following is the output:

For columns, you can set axis to columns. It has the same effect as using 0 or 1:

data.mean(axis='columns').head() 

The following is the output:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.159.164