0

I try to calculate some stats for a list. But somehow these are not correct: Code: import pandas as pd

import statistics


list_runs_stats=[4.149432, 3.133142, 3.182976, 2.620959, 3.200038, 2.66668, 2.604444, 2.683382, 3.249564, 3.149947]

list_stats=pd.Series(list_runs_stats).describe()

print (list_stats.mean())
print (list_stats.min())
print (list_stats.max())
print (list_stats.median())
print (list_stats.count())

Result:

3.6617099664905832
0.467574831924664
10.0
3.10280045
8

I think min, max and count is quite obvious that it is not correct. Excel gives me mean: 3.0640564 and median:3,1415445

What I am doing wrong?

Zio
  • 89
  • 5

2 Answers2

2

By assigning the output of describe() to list_stats, you are calculating the min and max of the output of describe function

Can you try this this instead?

import pandas as pd
list_runs_stats=[4.149432, 3.133142, 3.182976, 2.620959, 3.200038, 2.66668, 2.604444, 2.683382, 3.249564, 3.149947]
df = pd.Series(list_runs_stats)
df.describe()
#Output
count    10.000000
mean      3.064056
std       0.467575
min       2.604444
25%       2.670856
50%       3.141545
75%       3.195773
max       4.149432
dtype: float64
1

Seems like this post can help you out: Finding the average of a list

for example:

print(statistics.mean(list_runs_stats)) # would print 3.0640564
hjun
  • 73
  • 7
  • You have imported statistics library but you aren't using it. In order to use functions of the library, you need to specify it :) – hjun Nov 14 '22 at 09:26