Last active
May 4, 2018 08:38
-
-
Save new-village/a9beb865638fdef93e492963fcbda142 to your computer and use it in GitHub Desktop.
データフレームの各行にファンクションの結果をインサートする方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ジョッキーの複勝率の計算 | |
def cal_jockey(jid, rdt): | |
query = Result.objects.filter(jockey_id=jid, race__race_dt__lt=rdt).exclude(rank=0) | |
run_all = query.count() | |
run_t3 = query.filter(rank__lte=3).count() | |
ratio = round(run_t3 / run_all, 2) if run_all != 0 else 0 | |
return ratio | |
df["jockey_t3r"] = df.apply(lambda row: cal_jockey(row["jockey_id"], row["race_dt"]), axis=1) | |
df.head() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment