回答編集履歴
1
修正
test
CHANGED
@@ -22,33 +22,39 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
df = pd.read_table(io.StringIO(data), delimiter="\s+"
|
25
|
+
df = pd.read_table(io.StringIO(data), delimiter="\s+", index_col="state")
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
# ここから処理
|
32
|
+
|
33
|
+
df = df.reset_index()
|
26
34
|
|
27
35
|
print(df)
|
28
36
|
|
29
|
-
#
|
37
|
+
# state a b c
|
30
38
|
|
31
|
-
#
|
39
|
+
# 0 0 0 0 1
|
32
40
|
|
33
|
-
#
|
41
|
+
# 1 0 0 1 1
|
34
42
|
|
35
|
-
#
|
43
|
+
# 2 1 0 1 1
|
36
44
|
|
37
|
-
# 1 0 1 1
|
38
|
-
|
39
|
-
#
|
45
|
+
# 3 1 1 1 0
|
40
46
|
|
41
47
|
results = {}
|
42
48
|
|
43
|
-
for
|
49
|
+
for col in df.columns:
|
44
50
|
|
45
|
-
|
51
|
+
if col == "state":
|
46
52
|
|
47
|
-
|
53
|
+
continue
|
48
54
|
|
49
|
-
|
55
|
+
ratio = df.groupby(col).mean()
|
50
56
|
|
51
|
-
|
57
|
+
results[col] = ratio["state"]
|
52
58
|
|
53
59
|
df_results = pd.DataFrame(results)
|
54
60
|
|