# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import numpy as np
import pandas as pd

columns = ['Date', 'Home/Away', 'Game', 'Team', 'Player', 'Min',
               'FGM', 'FGA', 'FG%', '3PM', '3PA', '3P%', 'FTM', 'FTA',
               'FT%', 'OREB', 'DREB', 'REB', 'AST', 'STL', 'BLK', 'TOV', 
               'PF', 'PTS', '+/-']

nba1 = pd.read_csv('nba_97.csv', names=columns)
nba2 = pd.read_csv('nba_98-01.csv', names=columns)
nba3 = pd.read_csv('nba_02-03.csv', names=columns)
nba4 = pd.read_csv('nba_04.csv', names=columns)
nba5 = pd.read_csv('nba_96_05.csv', names=columns)
nba6 = pd.read_csv('nba_06-09.csv', names=columns)
nba7 = pd.read_csv('nba_10_11.csv', names=columns)
nba8 = pd.read_csv('nba_12.csv', names=columns)
nba9 = pd.read_csv('nba_12part2.csv', names=columns)
nba10 = pd.read_csv('nba_13_14.csv', names=columns)
nba11 = pd.read_csv('nba_15.csv', names=columns)
nba12 = pd.read_csv('nba_16-18.csv', names=columns)

data = pd.concat([nba1, nba2, nba3, nba4, nba5, nba6, nba7, nba8,
                  nba9, nba10, nba11, nba12])
data

# +
data['Date'] = pd.to_datetime(data['Date'])

data['Min'] = data['Min'].fillna('00:00')
data['Min'] = '00:'+data['Min']
data['Min'] = pd.to_timedelta(data['Min'])

data = data.fillna('DNP / INJ').reset_index(drop=True)

data.insert(0, 'Season', data['Game'].astype('str').str[1:3])

heights = pd.read_csv('player_heights.csv')
heights['Season'] = heights['Season'].astype('str').str.zfill(2).astype('object')
heights = heights.drop_duplicates(subset='Player')[['Player', 'Height (in)']]

data = pd.merge(data, heights, on=['Player'], how='left')
data = data.sort_values('Min', ascending=False).sort_values(['Date', 
                                              'Game', 'Home/Away'])
data['Height (in)'] = data['Height (in)'].fillna(79)

# +
#away = data[['Game', 'Team', 'Home/Away']].loc[data['Home/Away']=='Away']
#away_table = away.groupby('Game').first()
#away_table.to_csv('away_table.csv')
# -

data.to_csv('player_data.csv', index=False)



StarcoderdataJupyterScriptsDedupFiltered