teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

サンプル追加

2019/06/03 04:41

投稿

magichan
magichan

スコア15898

answer CHANGED
@@ -79,4 +79,77 @@
79
79
  #16 2 3 3 1 B C 2 2
80
80
  #17 2 3 4 2 B C 2 2
81
81
  #18 2 3 5 2 B C 2 2
82
+ ```
83
+
84
+ ---
85
+ ###【追記】
86
+ 動作確認サンプル その2
87
+
88
+ ```Python
89
+ import pandas as pd
90
+ import io
91
+
92
+ csv = """
93
+ ,week,match,set,game,team1,team2,game winner
94
+ 0,1,1,1,1,gamewith,detonation,1
95
+ 1,1,1,1,2,gamewith,detonation,1
96
+ 2,1,1,2,1,gamewith,detonation,2
97
+ 3,1,1,2,2,gamewith,detonation,1
98
+ 4,1,1,2,3,gamewith,detonation,2
99
+ 5,1,1,3,1,gamewith,detonation,2
100
+ 6,1,1,3,2,gamewith,detonation,1
101
+ 7,1,1,3,3,gamewith,detonation,1
102
+ 8,1,1,3,4,gamewith,detonation,1
103
+ 9,1,2,1,1,C,talon-espo,2
104
+ 10,1,2,1,2,C,talon-espo,1
105
+ 11,1,2,1,3,C,talon-espo,2
106
+ 12,1,2,2,1,C,talon-espo,2
107
+ 13,1,2,2,2,C,talon-espo,1
108
+ 14,1,2,2,3,C,talon-espo,1
109
+ 15,1,2,3,1,C,talon-espo,2
110
+ 16,1,2,3,2,C,talon-espo,1
111
+ 17,1,2,3,3,C,talon-espo,1
112
+ 18,1,2,3,4,C,talon-espo,2
113
+ 19,1,2,3,5,C,talon-espo,1
114
+ 20,1,3,1,1,bren-espo,sandbox,2
115
+ 21,1,3,1,2,bren-espo,sandbox,2
116
+ 22,1,3,2,1,bren-espo,sandbox,2
117
+ 23,1,3,2,2,bren-espo,sandbox,1
118
+ 24,1,3,3,1,bren-espo,sandbox,2
119
+ 25,1,3,3,2,bren-espo,sandbox,1
120
+ """
121
+
122
+ df = pd.read_csv(io.StringIO(csv), index_col=0)
123
+ print(df)
124
+
125
+ df['set winner'] = df.groupby(['match','set'])['game winner'].transform(lambda d:d.mode()[0])
126
+ df['match winner'] = df.groupby(['match'])['set winner'].transform(lambda d:d.mode()[0])
127
+ print(df)
128
+ # week match set game team1 team2 game winner setwinner matchwinner
129
+ #0 1 1 1 1 gamewith detonation 1 1 1
130
+ #1 1 1 1 2 gamewith detonation 1 1 1
131
+ #2 1 1 2 1 gamewith detonation 2 2 1
132
+ #3 1 1 2 2 gamewith detonation 1 2 1
133
+ #4 1 1 2 3 gamewith detonation 2 2 1
134
+ #5 1 1 3 1 gamewith detonation 2 1 1
135
+ #6 1 1 3 2 gamewith detonation 1 1 1
136
+ #7 1 1 3 3 gamewith detonation 1 1 1
137
+ #8 1 1 3 4 gamewith detonation 1 1 1
138
+ #9 1 2 1 1 C talon-espo 2 2 1
139
+ #10 1 2 1 2 C talon-espo 1 2 1
140
+ #11 1 2 1 3 C talon-espo 2 2 1
141
+ #12 1 2 2 1 C talon-espo 2 1 1
142
+ #13 1 2 2 2 C talon-espo 1 1 1
143
+ #14 1 2 2 3 C talon-espo 1 1 1
144
+ #15 1 2 3 1 C talon-espo 2 1 1
145
+ #16 1 2 3 2 C talon-espo 1 1 1
146
+ #17 1 2 3 3 C talon-espo 1 1 1
147
+ #18 1 2 3 4 C talon-espo 2 1 1
148
+ #19 1 2 3 5 C talon-espo 1 1 1
149
+ #20 1 3 1 1 bren-espo sandbox 2 2 1
150
+ #21 1 3 1 2 bren-espo sandbox 2 2 1
151
+ #22 1 3 2 1 bren-espo sandbox 2 1 1
152
+ #23 1 3 2 2 bren-espo sandbox 1 1 1
153
+ #24 1 3 3 1 bren-espo sandbox 2 1 1
154
+ #25 1 3 3 2 bren-espo sandbox 1 1 1
82
155
  ```