有人可以帮我编写以下代码的简单方法吗?这段代码有效,但是似乎很长,当我想重复一次时很费时间。我正在遍历行,但是我想在每次迭代期间在每行上运行几个.sum函数,并将该值放在新列中。
for ind, row in tqdm(df.iterrows()):
print("I'm Working ", end = '\r')
df.loc[ind,"pre_fighter_2_sig_str_totals_total_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_total_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_total_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_total_B"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_total_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_total_A"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_total_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_total_B"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_total_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_total_A"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_total_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_total_B"].sum()
df.loc[ind,"pre_fighter_1_td_totals_total_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_total_A"].sum()
df.loc[ind,"pre_fighter_1_td_totals_total_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_total_B"].sum()
df.loc[ind,"pre_fighter_2_td_totals_total_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_total_A"].sum()
df.loc[ind,"pre_fighter_2_td_totals_total_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_total_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round1_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round1_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round1_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round1_B"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round1_A"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round1_B"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round1_A"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round1_B"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round1_A"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round1_B"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round1_A"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round1_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round2_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round2_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round2_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round2_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round2_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round2_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round2_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round2_B"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round2_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round2_A"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round2_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round2_B"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round2_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round2_A"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round2_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round2_B"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round2_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round2_A"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round2_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round2_B"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round2_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round2_A"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round2_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round2_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round3_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round3_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round3_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round3_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round3_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round3_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round3_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round3_B"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round3_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round3_A"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round3_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round3_B"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round3_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round3_A"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round3_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round3_B"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round3_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round3_A"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round3_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round3_B"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round3_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round3_A"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round3_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round3_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round4_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round4_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round4_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round4_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round4_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round4_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round4_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round4_B"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round4_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round4_A"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round4_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round4_B"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round4_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round4_A"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round4_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round4_B"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round4_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round4_A"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round4_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round4_B"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round4_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round4_A"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round4_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round4_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round5_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round5_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_totals_round5_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_totals_round5_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round5_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round5_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_totals_round5_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_totals_round5_B"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round5_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round5_A"].sum()
df.loc[ind,"pre_fighter_1_total_str_totals_round5_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_total_str_totals_round5_B"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round5_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round5_A"].sum()
df.loc[ind,"pre_fighter_2_total_str_totals_round5_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_total_str_totals_round5_B"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round5_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round5_A"].sum()
df.loc[ind,"pre_fighter_1_td_totals_round5_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_td_totals_round5_B"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round5_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round5_A"].sum()
df.loc[ind,"pre_fighter_2_td_totals_round5_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_td_totals_round5_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_sig_str_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_sig_str_totals_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_sig_str_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_sig_str_totals_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_sig_str_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_sig_str_totals_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_sig_str_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_sig_str_totals_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_head_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_head_totals_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_head_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_head_totals_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_head_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_head_totals_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_head_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_head_totals_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_body_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_body_totals_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_body_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_body_totals_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_body_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_body_totals_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_body_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_body_totals_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_leg_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_leg_totals_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_leg_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_leg_totals_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_leg_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_leg_totals_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_leg_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_leg_totals_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_distance_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_distance_totals_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_distance_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_distance_totals_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_distance_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_distance_totals_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_distance_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_distance_totals_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_clinch_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_clinch_totals_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_clinch_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_clinch_totals_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_clinch_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_clinch_totals_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_clinch_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_clinch_totals_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_ground_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_ground_totals_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_ground_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_ground_totals_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_ground_totals_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_ground_totals_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_ground_totals_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_ground_totals_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_sig_str_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_sig_str_round1_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_sig_str_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_sig_str_round1_B"].sum()
df.loc[ind,"pre_fighter_2_sig_str_sig_str_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_sig_str_round1_A"].sum()
df.loc[ind,"pre_fighter_2_sig_str_sig_str_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["B_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_2_sig_str_sig_str_round1_B"].sum()
df.loc[ind,"pre_fighter_1_sig_str_head_round1_A_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_head_round1_A"].sum()
df.loc[ind,"pre_fighter_1_sig_str_head_round1_B_all_fights_1"] = df[(df["B_fighter"] == row["R_fighter"]) & (df["Original Index"] < row["Original Index"])]["fighter_1_sig_str_head_round1_B"].sum()
答案 0 :(得分:0)
在数组上找到一些模式并迭代键
例如
for ind, row in tqdm(df.iterrows()):
print("I'm Working ", end = '\r')
keys = [
"fighter_2_sig_str_totals_total_A",
"fighter_2_sig_str_totals_total_B",
...
]
b_fighter_rows = df["B_fighter"] == row["B_fighter"]
less_than_original_rows = df["Original Index"] < row["Original Index"]
for key in keys:
df.loc[ind, key + "_all_fights_1"] = df[(b_fighter_rows & less_than_original_rows)][key].sum()