0

I want to create a graph that combines these three variables. I want to do this so I can see if the team's average win rating has an effect on the home crowd attendance. I have attached an image of what my data frame looks like. I am open to multiple graphs and would love to look at multiple different solutions for this if possible! Link to the data frame is here

Here is an example code to get you started. nba = pd.DataFrame([['Spurs', 18459.4, .741800], ['Thunder', 18203.0, 676800], ['Clippers', 19203.4, .662600], ['Warriors', 19403.6, .650000]], columns = ['Team', 'Home: Avg Attendance', 'Winning Percentage'])

korny
  • 13
  • 4
  • Can you please include your dataframe as a copyable piece of code, rather than an image file (makes testing easier)? – Henry Ecker Apr 30 '21 at 03:09
  • @HenryEcker I am fairly new to Python so I am unsure what you are looking for when you say a copyable piece of code. This is a merged data frame between two Excel sheets. I was able to use the to_csv function and saved it to my computer. I am unable to upload a CSV in the question for some reason but I can send it to you some other way. – korny Apr 30 '21 at 03:47
  • See. [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888) – Henry Ecker Apr 30 '21 at 03:48
  • @HenryEcker Thank you! Editing original post with that code now! – korny Apr 30 '21 at 03:56

1 Answers1

0

The graph function of pandas python package, allows you to create a composite graph with the number of spectators and the winning percentage. This is the simplest example.

nba.set_index('Team', inplace=True)

nba['Home: Avg Attendance'].plot(kind='bar')
nba['Winning Percentage'].plot(secondary_y=True, style='g', rot=90, figsize=(12,6)

enter image description here

JIST
  • 1,139
  • 2
  • 8
  • 30
r-beginners
  • 31,170
  • 3
  • 14
  • 32
  • When I did this the graph was super squished together and I couldn't read any of the team names and the bar plots are too close together and not readable. Do you know how to stretch it out and make it readable? – korny Apr 30 '21 at 04:16
  • `figsize=(12,9)`For example, you can use this to set the size of the width and height. – r-beginners Apr 30 '21 at 04:20
  • I got it from your edit. Thank you for the help I appreciate it! :) – korny Apr 30 '21 at 04:21
  • If my answer helped you, please consider accepting it as the correct answer – r-beginners Apr 30 '21 at 04:21