Strange behaviour of mean() in python dataframes

Viewed 55

I have found this weird behaviour of mean function in pandas dataframes, basically given a dataframe "d", a column "x" d.mean()[x] != d[x].mean(), here is a reproduction of this behaviour:

from sklearn.datasets import  load_diabetes
import pandas as pd

data = load_diabetes()
df = pd.DataFrame(data.data, columns=data.feature_names)

print(df.mean()['age'])
#-1.4442946587318214e-18
print(df['age'].mean())
#-2.511816797794472e-19

There is any known explanation for this?

1 Answers

in my case it works correctly. I share my results

enter image description here

Related