-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepstats.py
47 lines (20 loc) · 872 Bytes
/
prepstats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Clean data file for use in app
# Data file comes from the pybaseball Database project
# All_stats.csv
import pandas as pd
df = pd.read_csv("All_Stats.csv")
df = df[df['Season_bat'] >= 2000]
df.loc[df["Season_bat"].isnull(),'Season_bat'] = df['Season_pit']
df.loc[df["Name_bat"].isnull(),'Name_bat'] = df['Name_pit']
df.loc[df["Team_bat"].isnull(),'Team_bat'] = df['Team_pit']
df.loc[df["Age_bat"].isnull(),'Age_bat'] = df['Age_pit']
df.loc[df["Season_pit"].isnull(),'Season_pit'] = df['Season_bat']
df.loc[df["Name_pit"].isnull(),'Name_pit'] = df['Name_bat']
df.loc[df["Team_pit"].isnull(),'Team_pit'] = df['Team_bat']
df.loc[df["Age_pit"].isnull(),'Age_pit'] = df['Age_bat']
df.fillna(0, inplace=True)
df = df.drop('Unnamed: 0_bat', 1)
df = df.drop('Unnamed: 0_pit', 1)
print(df.head())
df.to_csv('All_Stats.csv')
print('successful')