简体   繁体   中英

How to plot after doing a groupby on pandas data frame

I have a time series data which contains date, year, month and ratings columns. I have grouped by year and month and and then i am counting the number of rating in each month for that year. I have done this the following way:

nightlife_ratings_mean = review_data_nightlife.groupby(['year','month'])['stars'].count()

I get the following data frame

year  month
2005  8           3
      9           4
      10         16
      11         13
      12          7
2006  1          62
      2          24
      3          13
      4          20
      5          11
      6          13
      7          11
      8          29
      9          33
      10         46

I want to plot this such that my x label is year and and y label is count and i want a line plot with marker-ø. How can I do this. I am trying this for the first time. So please help.

You can call plot on your DataFrame and include the option style = 'o-' :

plt = nightlife_ratings_mean.plot(x = 'year', y = 'stars', style = 'o-', title = "Stars for each month and year")
plt.set_xlabel("[Year, Month]")
plt.set_ylabel("Stars")

This will plot the following:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM