I would like to set the precision of the mean value in a dataframe, but I get the following error: TypeError: cannot convert the series to <class 'float'>
I set the arrays as dtype=float. It works if I remove "%.2f"%, but gives more decimal points than I want.
Following is the code:
import numpy as np
import pandas as pd
df = pd.DataFrame(np.array([[0, 0.030, 0.031, 0.032], [10, 0.153, 0.155, 0.154], [20, 0.393, 0.397, 0.395]]), columns=['Y0','Y1', 'Y2', 'Y3'], dtype=float)
Xa=df.loc[:,"Y1":]
mean=Xa.mean(axis=1)
df['mean']="%.2f"%mean
df