df['avg'] = df.mean(axis=1) Monday Tuesday Wednesday avg Mike 42 NaN 12 27.000000 Jenna NaN NaN 15 15.000000 Jon 21 4 1 8.666667
Here is what the above code is Doing:
1. We create a new column called ‘avg’ and set it equal to the mean of the other columns.
2. We use the axis=1 parameter to tell Python that we want to calculate the mean of each row, not column.
3. We use the inplace=True parameter to tell Python that we want to change our existing DataFrame, instead of creating a new one.