回答編集履歴
1
修正
answer
CHANGED
@@ -10,20 +10,23 @@
|
|
10
10
|
1 0 1 1
|
11
11
|
1 1 1 0"""
|
12
12
|
|
13
|
-
df = pd.read_table(io.StringIO(data), delimiter="\s+"
|
13
|
+
df = pd.read_table(io.StringIO(data), delimiter="\s+", index_col="state")
|
14
|
+
|
15
|
+
|
16
|
+
# ここから処理
|
17
|
+
df = df.reset_index()
|
14
18
|
print(df)
|
15
|
-
#
|
19
|
+
# state a b c
|
16
|
-
# state
|
17
|
-
# 0 0 0 1
|
20
|
+
# 0 0 0 0 1
|
18
|
-
# 0 0 1 1
|
19
|
-
# 1 0 1 1
|
21
|
+
# 1 0 0 1 1
|
22
|
+
# 2 1 0 1 1
|
20
|
-
#
|
23
|
+
# 3 1 1 1 0
|
21
24
|
results = {}
|
22
|
-
for i in [0,1]:
|
23
|
-
results[i] = {}
|
24
|
-
|
25
|
+
for col in df.columns:
|
26
|
+
if col == "state":
|
27
|
+
continue
|
25
|
-
|
28
|
+
ratio = df.groupby(col).mean()
|
26
|
-
|
29
|
+
results[col] = ratio["state"]
|
27
30
|
df_results = pd.DataFrame(results)
|
28
31
|
print(df_results)
|
29
32
|
# 0 1
|