We will use skipna=True to ignore the null or NA data. Let us check what happens if it is set to True ( skipna=True )
import numpy as np
import pandas as pd
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
'ID':[1,2,3,4,5,6],
'MATH':[80,40,70,70,70,30],
'ENGLISH':[80,70,np.nan,50,60,30]}
my_data = pd.DataFrame(data=my_dict)
print(my_data.mean(skipna=True))
Output
ID 3.5
MATH 60.0
ENGLISH 58.0
dtype: float64
We will use skipna=False
print(my_data.mean(skipna=False))
Output
ID 3.5
MATH 60.0
ENGLISH NaN
dtype: float64
numeric_only
Default value is None, we can set it to True ( numeric_only=True ) to include only float, int, boolean columns. We can included all by setting it to False ( numeric_only=False ) . Let us see the outputs .
print(my_data.mean(numeric_only=False))
This will generate error as we have string objects.
TypeError: could not convert string to float: 'RaviRajuAlexRonKingJack'