Plotting on specific column values in Python

772 views python

I've got values that repeat by the HOUR for every month in every year like:

Year    Month     HOUR  NAME            RATE
2010    1          0    Big              2  
2010    1          0    Channelview      4
2010    1          0    Cottonwood       12
2010    1          1    Big              4  
2010    1          1    Channelview      9
2010    1          1    Cottonwood       11

I'd like to plot this RATE data (y-axis) by the HOUR (x-axis) for the NAME for each month in the year (goes for 7 years). Is there a way in doing this by .groupby or .loc without having to create extra dataframes based off the year and month?

answered question

1 Answer


You can do this using groupby:

for name, data in df.groupby('NAME'):
    plt.plot(data['HOUR'], data['RATE'], label=name)


enter image description here

posted this

Have an answer?


Please login first before posting an answer.