Ahmad
Ahmad

Reputation: 9658

Dataframe mean returns empty series

I have a dataframe as follows. I want to get the mean of column pred1_score as a number. However, my attempt returns an empty series. Could you please help me?

>>> df1.head()
   Unnamed: 0 Unnamed: 0.1 compare  ... preds_score pred1_score pred2_score
0         0.0            0      //  ...      0.6045      0.6195      0.5272
1         1.0            1      //  ...      0.6045      0.5403      0.4759
2         2.0            2      //  ...      0.6045      0.3759      0.3636
3         3.0            3      //  ...      0.6045      0.5923      0.5187
4         4.0            4      //  ...      0.6045      0.5926      0.4553

[5 rows x 13 columns]
>>> df1[["pred1_score"]].mean()
Series([], dtype: float64)

I also tried:

df1[['pred1_score']].astype(float).mean()

But it throws:

ValueError: could not convert string to float: 'pred1_score'

Which could be the column head.

Upvotes: 0

Views: 958

Answers (1)

Felix K Jose
Felix K Jose

Reputation: 892

Instead of df1[["pred1_score"]].mean() please try df1.pred1_score.astype('float').mean()

Upvotes: 1

Related Questions