text_plain_output_1.png
"""
def count_not_na(row, home):
    number_previous_games = row[f"number_{home}_previous_games"]
    if number_previous_games!=10:
        number_previous_games+=1
    else:
        return 0
    count_notna = 0
    historical_columns_template_home = [x for x in historical_columns_template if x.startswith(home)]
    for column in historical_columns_template_home:
        if pd.notna(row[column+f"_{number_previous_games}"]):
            count_notna+=1
    return count_notna
def count_na_10(row, home):
    number_previous_games = row[f"number_{home}_previous_games"]
    if number_previous_games!=10:
        return 0
    else:
        count_na = 0
        historical_columns_template_home = [x for x in historical_columns_template if x.startswith(home)]
        for column in historical_columns_template_home:
            if pd.isna(row[column+f"_{number_previous_games}"]):
                count_na+=1
        return count_na
train_df["number_notna_home_previous_games"] = train_df.apply(lambda row: count_not_na(row, "home"), axis=1)
train_df["number_notna_away_previous_games"] = train_df.apply(lambda row: count_not_na(row, "away"), axis=1)
train_df["number_na10_home_previous_games"] = train_df.apply(lambda row: count_na_10(row, "home"), axis=1)
train_df["number_na10_away_previous_games"] = train_df.apply(lambda row: count_na_10(row, "away"), axis=1)
"""