3

I am trying to calulate standard deviation for numbers from 1 to 7

I get different results for numpy and for pandas. I am sure that the result should be 2:

>>> df = pd.DataFrame({'vals': [1, 2, 3, 4, 5, 6, 7]})
>>> df["vals"].std()
2.160246899469287
>>> df["vals"].mean()
4.0

>>>np.std([1, 2, 3, 4, 5, 6, 7])
2.0
>>>np.mean([1, 2, 3, 4, 5, 6, 7])
4.0

What is wrong here?

3
  • (cannot reproduce) Commented Mar 23, 2018 at 18:40
  • 3
    do: np.std(df['vals'], ddof=1) you get the same answer. Commented Mar 23, 2018 at 18:41
  • 2
    This is my dup for numpy vs pandas std, but I have trouble believing df["vals"].mean() gave 2. Commented Mar 23, 2018 at 18:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.