Python Forum
Help creating a histogram using an array - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Help creating a histogram using an array (/thread-9588.html)



Help creating a histogram using an array - rubadub - Apr-17-2018

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!