text_plain_output_1.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

pd.set_option('display.max_columns', None)

train_df = pd.read_csv('/kaggle/input/football-match-probability-prediction/train.csv')
test_df = pd.read_csv('/kaggle/input/football-match-probability-prediction/test.csv')
sample_sub = pd.read_csv('/kaggle/input/football-match-probability-prediction/sample_submission.csv')

def number_of_previous_games(row, home):
    for i in range(1, 11):
        col = f'{home}_team_history_match_date_{i}'
        if pd.isna(row[col]):
            return i - 1
    return i
train_df['number_home_previous_games'] = train_df.apply(lambda row: number_of_previous_games(row, 'home'), axis=1)
train_df['number_away_previous_games'] = train_df.apply(lambda row: number_of_previous_games(row, 'away'), axis=1)
test_df['number_home_previous_games'] = test_df.apply(lambda row: number_of_previous_games(row, 'home'), axis=1)
test_df['number_away_previous_games'] = test_df.apply(lambda row: number_of_previous_games(row, 'away'), axis=1)

train_df['number_home_previous_games'].describe()