python
1sample.head() 2 3# output 4 team1 team2 50 1107 1112 61 1107 1116 72 1107 1124 83 1107 1125 94 1107 1129 10 11vict_teams.head() 12 13# output 14 TeamID vict_per 150 1181 0.808072 161 1242 0.808783 172 1246 0.768182 183 1314 0.755176 194 1112 0.758557 20 21print(vict_teams.shape,sample_submission.shape) 22 23# output 24(366, 2) (11390, 2)
上記の様なsample,vict_teamsというdataframe形式のファイルに対して、
sampleに新たなカラム"pred"を追加したいと考えています。
predの内容は、
0.99 ((team1のnumberにおけるvict_teams["TeamID"]のvict_per) >= (team2のnumberにおけるvict_teams["TeamID"]のvict_per))
0.01 ((team1のnumberにおけるvict_teams["TeamID"]のvict_per) < (team2のnumberにおけるvict_teams["TeamID"]のvict_per))
としたいと思います。
(具体的にはsampleの0行目を採用すると、
vict_teams[vict_teams["TeamID"] == 1107] >=
vict_teams[vict_teams["TeamID"] == 1112]
ならsample["pred"][0] = 0.99
となる感じです。)
上記の様にcodeを書いてみたのですが、数が多すぎる為、上手く機能しない様です。
解決するためのうまいcodeがあれば、ご教授頂けますと幸いです。宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/29 11:25