Python Forum
Help creating a histogram using an array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help creating a histogram using an array
#1
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating 2D Array jpinko 1 2,182 Nov-23-2020, 09:05 PM
Last Post: jefsummers
  Creating look up table/matrix from 3d data array chai0404 3 2,824 Apr-09-2020, 04:53 AM
Last Post: buran
  How to fit a 2D histogram like in ROOT? Zandar 2 4,067 Aug-06-2019, 03:01 PM
Last Post: Zandar
  while creating a array using numpy.arrange, how to negate only the last 50 numbers? vicky53 1 2,645 Apr-06-2019, 11:52 AM
Last Post: scidam
  creating an empty NumPy array in Python sandeepatel 2 4,639 Jan-16-2019, 09:24 AM
Last Post: rinu
  histogram error alyssaantarctica 1 3,714 Jul-09-2018, 10:46 PM
Last Post: Larz60+
  Plot Probability Density of an Histogram Python_TLS 1 2,853 Jun-28-2018, 06:19 AM
Last Post: scidam
  histogram with matplotlib vaugirard 10 6,152 Jun-01-2018, 04:13 AM
Last Post: vaugirard
  Histogram help dandatadan 1 2,512 Nov-25-2017, 06:07 AM
Last Post: heiner55
  mcerp: error while plotting a histogram rakhmadiev 2 4,474 Apr-02-2017, 09:08 PM
Last Post: rakhmadiev

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020