Creating single chart from three categoric values using python

Viewed 30

I am fairly new to python and its terminology and can be clumsy at describing the problem.Sorry for that.

What I got is three cities that produced three fruits for two years, and I need to draw the single-static chart that summarizes the data best.

The fact that dataframe have 3 categoric values (city, fruits and year) and one measure makes me confused.

At first I try to use stack bar chart, however If I use fruits in the bars and cities in X axis, I could not find where to use year value. I tried to use pivot method to convert year value into measure, but I could not advance with two measures this time. I mainly used Matplotlib. Any help appreciated,

data= {
    'city':['amsterdam','amsterdam','amsterdam','amsterdam','amsterdam','amsterdam','paris','paris','paris','paris','paris','paris','berlin','berlin','berlin','berlin','berlin','berlin'],
    'fruits':['apples','oranges','bananas','apples','oranges','bananas','apples','oranges','bananas','apples','oranges','bananas','apples','oranges','bananas','apples','oranges','bananas'],
    'year':[2000,2000,2000,2001,2001,2001,2000,2000,2000,2001,2001,2001,2000,2000,2000,2001,2001,2001],
    'amount':[384,289,347,242,390,274,175,334,245,116,252,366,255,400,300,240,600,180] 
  }

df=pd.DataFrame(data)

df.head()

city fruits year amount
0 paris apples 2000 384
1 paris oranges 2000 289
2 paris bananas 2000 347
3 paris apples 2001 242
4 paris oranges 2001 390
0 Answers
Related