Python Forum
Plotting histogram of dataframe column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plotting histogram of dataframe column
#1
I have the answer, but I don't understand it:

from matplotlib import pyplot as plt
%matplotlib inline #Jupiter notebook
plt.style.use('seaborn')

# Plot a histogram of combined points
plt.hist(super_bowls.combined_pts)
plt.xlabel('Combined Points')
plt.ylabel('Number of Super Bowls')
plt.show()

# Display the highest- and lowest-scoring Super Bowls
display(super_bowls[super_bowls['combined_pts'] > 70])
Please compare lines 6 and 12. Why does the syntax for plot.hist include a dot between the name of dataframe (super_bowls) and column in that df (combined_pts)?

Line 12, in contrast, uses two brackets to look up (I think) rows in a dataframe for whom the combined_pts column value is greater than 70.

Thanks!

I just learned .columns is a component of DataFrames. I can print(super_bowl.combined_pts) to get a 2-column list of row # and combined points.

This helps me understand line 6.

Why does Line 12 require the double brackets, though?
Reply
#2
The dataframe understands slices. So in English line 12 would be Display super_bowls where super_bowls combined points is greater than 70.
Reply
#3
(Jul-29-2020, 04:06 PM)jefsummers Wrote: The dataframe understands slices. So in English line 12 would be Display super_bowls where super_bowls combined points is greater than 70.

Why couldn't I have used a dot there since .columns is a component of DF's?
Reply
#4
You can.
display(super_bowls[super_bowls.combined_pts > 70])
should work
Reply
#5
(Jul-29-2020, 09:01 PM)jefsummers Wrote: You can.
display(super_bowls[super_bowls.combined_pts > 70])
should work

Seriously?? I'm so confused... I'll have to study this.

Thanks Jef!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Need help with NumPy Histogram function coding Triikey 1 946 May-15-2023, 01:45 PM
Last Post: deanhystad
  Can someone find out what kind of histogram is it? J_tin 1 1,805 Apr-26-2020, 05:23 PM
Last Post: buran
  typeerror, building histogram from data newatpython11 7 3,795 Jul-17-2019, 12:54 PM
Last Post: ichabod801
  Histogram using pandas dataframe not showing proper output ift38375 1 2,202 Jul-04-2019, 10:43 PM
Last Post: scidam
  Histogram and text file. pawlo392 1 4,137 May-24-2019, 03:14 AM
Last Post: heiner55
  how do i use get for my histogram function? pseudo 4 4,830 Oct-14-2018, 04:23 AM
Last Post: stullis

Forum Jump:

User Panel Messages

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