Python Forum

Full Version: Help creating a histogram using an array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, so I'm currently struggling on a piece of code. I'm not very proficient at Python so bear with me. What I have is a numpy array of baseball statistics with 20 columns and a lot of rows and two of the columns are the year the stats were taken from and a unique player id that only applies to this one person. As some players returned for more than a year, some of the player ids repeat in later rows. There is also a column with the number of runs that player got in a year.

What I'm trying to accomplish with this is make a histogram where the x axis is total number of runs a player got and the y axis is number of players who got these many runs, with 100 bins.

I used np.unique to make an array with the player ids only listed once and I know I need some weird kind of for loop to add all the runs to the player id, then I probably need an array with 2 columns, being the id and the runs gotten by that id, and a where statement to get the number of players with a certain amount of runs within a range to then be graphed.

Any help is appreciated. Thanks!