SANM2009
SANM2009

Reputation: 1998

Pandas Plotting Multi Value Data over a period

I need some help to plot some data in pandas, any help will be appreciated.

Dataframe looks like this:

    Item  Year Price  Quantity
0   Book  2000    $2        50
1  Table  2000   $33        44
2  Chair  2000   $21        31
3   Book  2001    $3        77
4  Table  2001   $20       500
5  Chair  2001    $2        50
6   Book  2002   $36         7
7  Table  2002  $200        50
8  Chair  2002   $44         5

I need to plot "Price" and "Quantity" for each item in "Item" over the years in "Year" column.

Upvotes: 0

Views: 199

Answers (1)

rpanai
rpanai

Reputation: 13437

I'm not sure about what you want but maybe you can start play from this

import pandas as pd
import numpy as np
df = pd.DataFrame({"Item": ["Book","Table","Chair"]*3,
              "Year":np.sort(list(range(2000,2003))*3),
              "Price":np.random.randint(2,200,9),
              "Quantity":np.random.randint(5,500,9)})
df1 = df.groupby(["Item","Year"]).apply(lambda x:x.sort_values("Year") )
del df1["Year"]
del df1["Item"]
df1.plot(kind="bar")

EDIT

Maybe this answer can help you.

Upvotes: 1

Related Questions