Last active
August 29, 2015 13:56
-
-
Save kellycampbell/9289884 to your computer and use it in GitHub Desktop.
Shows the distribution of batting averages for MLB players by the handedness they bat with. (Right, Left, Both)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas | |
| from ggplot import * | |
| # Shows the distribution of batting averages for MLB players by the handedness they bat with. (Right, Left, Both) | |
| def compare_averages(filename): | |
| """ | |
| Data from: https://www.dropbox.com/s/xcn0u2uxm8c4n6l/baseball_data.csv | |
| Example output: http://imgur.com/21Rs287 | |
| """ | |
| data = pandas.read_csv(filename) | |
| plotdata = data[data['avg'] != 0] # filters out players with no batting average | |
| p = ggplot(aes(x='avg', color='handedness'), data=plotdata) \ | |
| + geom_density() \ | |
| + labs(x="Batting Average", y="Density") | |
| print p | |
| if __name__ == "__main__": | |
| compare_averages('baseball_data.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment