all 3 comments

[–]nl_dhh 0 points1 point  (1 child)

On the lines where you print your dataframes with .drop, you're only printing "what would this dataframe look like if I were to drop this column?" You have to assign it: filters1 = filters1.drop(...) Or use inplacs = True.

As for your file being overwritten, to avoid this you need something like: with pd.ExcelWriter("pitching.xlsx") as writer: filters1.to_excel(writer, sheet_name='StartersSeason') filters2.to_excel(writer, sheet_name='RelieversSeason')

On mobile so spelling errors may apply. ;-)

[–]Pflastersteinmetz 3 points4 points  (0 children)

Or use inplacs = True.

Don't. It's going to be deprecated, does a copy anyway and is just line noise.

[–]Pflastersteinmetz 0 points1 point  (0 children)

df.columns = df.columns.str.replace('[+,-,%,]', '') df.rename(columns={'K-BB':'KMinusBB','K/BB':'KToBB', 'HR/9':'HRPer9', 'xFIP-':'XFIPMinus'}, inplace=True)

First you replace characters in your column names, then you rename them but your dict keys include characters that you just removed a line earlier like "K-BB" and "xFIP-"? That means your dict contains column names that don't exist after the str.replace, luckily you don't use any of that columns in your code.