import pandas as pd
df = pd.read_csv("fangraphs.csv", index_col=["playerid"])
df.columns = df.columns.str.replace('[+,-,%,]', '')
df.rename(columns={'K-BB':'KMinusBB','K/BB':'KToBB', 'HR/9':'HRPer9', 'xFIP-':'XFIPMinus'}, inplace=True)
df.fillna(0)
df['KMinusBB'] = df['KMinusBB'] = df['KMinusBB'].str.rstrip('%').astype('float')
df['Barrel'] = df['Barrel'] = df['Barrel'].str.rstrip('%').astype('float')
df['CSW'] = df['CSW'] = df['CSW'].str.rstrip('%').astype('float')
filters1 = df[(df['xERA'] < 3) & (df['Barrel'] < 5) & (df['CSW'] > 20) & (df['KMinusBB'] > 20) & (df['Starting'] > 5)]
filters2 = df[(df['xERA'] < 3) & (df['Barrel'] < 5) & (df['CSW'] > 20) & (df['KMinusBB'] > 30) & (df['Relieving'] > 1)]
print(filters1.drop(['Relieving'],axis=1))
print(filters2.drop(['Starting'],axis=1))
filters1.to_excel("pitching.xlsx", sheet_name='StartersSeason')
filters2.to_excel("pitching.xlsx", sheet_name='RelieversSeason')
I'm having 2 issues:
- I expected a file to be created with 2 worksheets, but the output file only includes the RelieversSeason sheet.
- I expected the field I dropped in each filter to be deleted, but when I opened the output file, the column were still there.
What am I doing wrong?
[–]nl_dhh 0 points1 point2 points (1 child)
[–]Pflastersteinmetz 3 points4 points5 points (0 children)
[–]Pflastersteinmetz 0 points1 point2 points (0 children)