回答編集履歴

1

サンプル追加

2019/06/03 04:41

投稿

magichan
magichan

スコア15898

test CHANGED
@@ -161,3 +161,149 @@
161
161
  #18 2 3 5 2 B C 2 2
162
162
 
163
163
  ```
164
+
165
+
166
+
167
+ ---
168
+
169
+ ###【追記】
170
+
171
+ 動作確認サンプル その2
172
+
173
+
174
+
175
+ ```Python
176
+
177
+ import pandas as pd
178
+
179
+ import io
180
+
181
+
182
+
183
+ csv = """
184
+
185
+ ,week,match,set,game,team1,team2,game winner
186
+
187
+ 0,1,1,1,1,gamewith,detonation,1
188
+
189
+ 1,1,1,1,2,gamewith,detonation,1
190
+
191
+ 2,1,1,2,1,gamewith,detonation,2
192
+
193
+ 3,1,1,2,2,gamewith,detonation,1
194
+
195
+ 4,1,1,2,3,gamewith,detonation,2
196
+
197
+ 5,1,1,3,1,gamewith,detonation,2
198
+
199
+ 6,1,1,3,2,gamewith,detonation,1
200
+
201
+ 7,1,1,3,3,gamewith,detonation,1
202
+
203
+ 8,1,1,3,4,gamewith,detonation,1
204
+
205
+ 9,1,2,1,1,C,talon-espo,2
206
+
207
+ 10,1,2,1,2,C,talon-espo,1
208
+
209
+ 11,1,2,1,3,C,talon-espo,2
210
+
211
+ 12,1,2,2,1,C,talon-espo,2
212
+
213
+ 13,1,2,2,2,C,talon-espo,1
214
+
215
+ 14,1,2,2,3,C,talon-espo,1
216
+
217
+ 15,1,2,3,1,C,talon-espo,2
218
+
219
+ 16,1,2,3,2,C,talon-espo,1
220
+
221
+ 17,1,2,3,3,C,talon-espo,1
222
+
223
+ 18,1,2,3,4,C,talon-espo,2
224
+
225
+ 19,1,2,3,5,C,talon-espo,1
226
+
227
+ 20,1,3,1,1,bren-espo,sandbox,2
228
+
229
+ 21,1,3,1,2,bren-espo,sandbox,2
230
+
231
+ 22,1,3,2,1,bren-espo,sandbox,2
232
+
233
+ 23,1,3,2,2,bren-espo,sandbox,1
234
+
235
+ 24,1,3,3,1,bren-espo,sandbox,2
236
+
237
+ 25,1,3,3,2,bren-espo,sandbox,1
238
+
239
+ """
240
+
241
+
242
+
243
+ df = pd.read_csv(io.StringIO(csv), index_col=0)
244
+
245
+ print(df)
246
+
247
+
248
+
249
+ df['set winner'] = df.groupby(['match','set'])['game winner'].transform(lambda d:d.mode()[0])
250
+
251
+ df['match winner'] = df.groupby(['match'])['set winner'].transform(lambda d:d.mode()[0])
252
+
253
+ print(df)
254
+
255
+ # week match set game team1 team2 game winner setwinner matchwinner
256
+
257
+ #0 1 1 1 1 gamewith detonation 1 1 1
258
+
259
+ #1 1 1 1 2 gamewith detonation 1 1 1
260
+
261
+ #2 1 1 2 1 gamewith detonation 2 2 1
262
+
263
+ #3 1 1 2 2 gamewith detonation 1 2 1
264
+
265
+ #4 1 1 2 3 gamewith detonation 2 2 1
266
+
267
+ #5 1 1 3 1 gamewith detonation 2 1 1
268
+
269
+ #6 1 1 3 2 gamewith detonation 1 1 1
270
+
271
+ #7 1 1 3 3 gamewith detonation 1 1 1
272
+
273
+ #8 1 1 3 4 gamewith detonation 1 1 1
274
+
275
+ #9 1 2 1 1 C talon-espo 2 2 1
276
+
277
+ #10 1 2 1 2 C talon-espo 1 2 1
278
+
279
+ #11 1 2 1 3 C talon-espo 2 2 1
280
+
281
+ #12 1 2 2 1 C talon-espo 2 1 1
282
+
283
+ #13 1 2 2 2 C talon-espo 1 1 1
284
+
285
+ #14 1 2 2 3 C talon-espo 1 1 1
286
+
287
+ #15 1 2 3 1 C talon-espo 2 1 1
288
+
289
+ #16 1 2 3 2 C talon-espo 1 1 1
290
+
291
+ #17 1 2 3 3 C talon-espo 1 1 1
292
+
293
+ #18 1 2 3 4 C talon-espo 2 1 1
294
+
295
+ #19 1 2 3 5 C talon-espo 1 1 1
296
+
297
+ #20 1 3 1 1 bren-espo sandbox 2 2 1
298
+
299
+ #21 1 3 1 2 bren-espo sandbox 2 2 1
300
+
301
+ #22 1 3 2 1 bren-espo sandbox 2 1 1
302
+
303
+ #23 1 3 2 2 bren-espo sandbox 1 1 1
304
+
305
+ #24 1 3 3 1 bren-espo sandbox 2 1 1
306
+
307
+ #25 1 3 3 2 bren-espo sandbox 1 1 1
308
+
309
+ ```