I have a Pandas DataFrame that contains multiple columns and multiIndex. I would like to plot data from two columns(“Total” and ”Sold”) as different line charts and use the values from the third column “Percentage” as the text of the annotation for the points on the “Sold” chart. What is the best way to do it? Any advice and suggestions will be greatly appreciated.
#data is a dict
data = { 'Department': ['Furniture','Furniture','Furniture',
'Gifts','Gifts','Gifts'],
'Month':['May','June','July','May','June','July'],
'Total':[2086,1740,1900,984,662,574],
'Sold':[201,225,307,126,143,72],
'Percentage':[10, 13, 16, 13, 22, 13]
}
# DataFrame() turns the dict into a DataFrame
# Set up MultiIndex
df=pd.DataFrame(data)
df.set_index(['Department', 'Month'], inplace=True)
df
DataFrame
# Plot departments
departments=df.index.get_level_values(0).unique()
for department in departments:
ax=df.ix[department].plot(title=department,y=['Total','Sold'],
xlim=(-1.0, 3.0))
Plot from DataFrame