简体   繁体   中英

Plotting Pandas dataframe matplotlib

I'm using Pandas to read in a .csv file containing dates and a product type and I'm trying to graph the amount of each product over time. Heres my current code:

    df = df.dropna()
    df= df[df['product'].str.contains("X|Y|Z")]
    df=df.groupby('date')['product'].value_counts()

which returns me this dataframe:

date        product
2013.0      X         2229
            Y         194
            Z         590
2014.0      X         229
            Y         1924
            Z         5902

Whats the best way to plot this using matplotlib?

Case 1

df.unstack().plot.bar()

在此处输入图片说明

Case 2

df.unstack(0).plot.bar()

在此处输入图片说明

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