text_html_output_1.png application_vnd.jupyter.stderr_output_1.png
import pandas as pd

import pandas as pd
df = pd.read_csv('/kaggle/input/nbagameinfo/nba_games (1).csv', index_col=0)
df

df = df.sort_values('date')
df

df = df.reset_index(drop=True)
df.drop(['mp.1', 'mp_opp.1', 'index_opp'], axis=1, inplace=True)

def add_target(team):
    team['target'] = team['won'].shift(-1)
    return team
df = df.groupby('team', group_keys=False).apply(add_target)
df[df['team'] == 'LAL']

df['target'][pd.isnull(df['target'])] = 2
df['target'] = df['target'].astype(int, errors='ignore')
nulls = pd.isnull(df)
nulls = nulls.sum()
nulls = nulls[nulls > 0]
valid_columns = df.columns[~df.columns.isin(nulls.index)]
df = df[valid_columns].copy()
df