Python List Statistics not correct

Question:

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?

Asked By: Zio

||

Answers:

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
Answered By: abhilash966

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
Answered By: hjun

instead with printing check with print(list_stats) or display in Jupiter.
print(list_stats)

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

or use dict form for print like
list_stats["min"]

Answered By: krishna
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.