When returning the pd.mean(), how to show only specific information?
Example
Now it gives this:
new_df = pd.read_excel('example.xls', usecols = ['weight'] )
print('avg value for column weight is here: '+ str(data.mean()))
Result
avg value for column weight is here: weight 2311.000000 dtype: float64
it should return:
avg value for column weight is here: 2311.000000
>Solution :
For avoid one value Series select column weight. If use Series.mean – call function for one column get scalar output:
print('avg value for column weight is here: '+ str(data['weight'].mean()))
Or use f-strings for same ouput:
print(f'avg value for column weight is here: {data["weight"].mean()}')