回答編集履歴
3
追記
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
-
|
33
|
+
どうしてもstatisticsでやりたい場合は、data_listを1次元に落とし込んでから使う手もあります。
|
34
34
|
|
35
35
|
```python3
|
36
36
|
|
@@ -38,18 +38,18 @@
|
|
38
38
|
|
39
39
|
import statistics
|
40
40
|
|
41
|
-
import numpy as np
|
42
|
-
|
43
41
|
|
44
42
|
|
45
43
|
df = pd.DataFrame([[1, 2], [1, 3], [4, 6]], columns=['A', 'B'])
|
46
44
|
|
47
45
|
data_list = df.values.tolist()
|
48
46
|
|
47
|
+
data_list = sum(data_list, []) # [1, 2, 1, 3, 4, 6]
|
48
|
+
|
49
|
-
hensa =
|
49
|
+
hensa = statistics.pstdev(data_list)
|
50
50
|
|
51
51
|
print("標準偏差=",hensa)
|
52
52
|
|
53
|
-
# 標準偏差= 1.9
|
53
|
+
# 標準偏差= 1.7716909687891083
|
54
54
|
|
55
55
|
```
|
2
追記
test
CHANGED
@@ -27,3 +27,29 @@
|
|
27
27
|
# 標準偏差= 1.7716909687891083
|
28
28
|
|
29
29
|
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
不偏推定量はこちら
|
34
|
+
|
35
|
+
```python3
|
36
|
+
|
37
|
+
import pandas as pd
|
38
|
+
|
39
|
+
import statistics
|
40
|
+
|
41
|
+
import numpy as np
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
df = pd.DataFrame([[1, 2], [1, 3], [4, 6]], columns=['A', 'B'])
|
46
|
+
|
47
|
+
data_list = df.values.tolist()
|
48
|
+
|
49
|
+
hensa = np.std(data_list, ddof=1)
|
50
|
+
|
51
|
+
print("標準偏差=",hensa)
|
52
|
+
|
53
|
+
# 標準偏差= 1.9407902170679516
|
54
|
+
|
55
|
+
```
|
1
コード修正
test
CHANGED
@@ -20,10 +20,10 @@
|
|
20
20
|
|
21
21
|
data_list = df.values.tolist()
|
22
22
|
|
23
|
-
hensa = np.std(data_list
|
23
|
+
hensa = np.std(data_list)
|
24
24
|
|
25
25
|
print("標準偏差=",hensa)
|
26
26
|
|
27
|
-
# 標準偏差= 0
|
27
|
+
# 標準偏差= 1.7716909687891083
|
28
28
|
|
29
29
|
```
|