Skip to content

Instantly share code, notes, and snippets.

@new-village
Last active May 4, 2018 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save new-village/a9beb865638fdef93e492963fcbda142 to your computer and use it in GitHub Desktop.
Save new-village/a9beb865638fdef93e492963fcbda142 to your computer and use it in GitHub Desktop.
データフレームの各行にファンクションの結果をインサートする方法
# ジョッキーの複勝率の計算
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