Let us say we have a dataframe as under:
index = pd.MultiIndex.from_tuples(zip(['A','A','A','A','B','B','B','B'],[2012,2013,2014,2015,2012,2013,2014,2015]))
df = pd.DataFrame({
'col1':[10,20,10,30,50,20,60,80],
'col2':[40,20,40,30,50,20,60,80],
'col3':[10,20,80,30,80,20,80,10],
},index=index)
I then added the names for these multi-index as 'Product' and 'Year' respectively.
Now I need to plot this data in such a way that for each 'Product' there is a different line for a specific column.
I tried this but it doesn't work.
df.plot(kind='line',x='Year')
I tried unstacking the dataframe using unstack(), however, as there are multiple columns, I will have to create as many new dataframes as there are columns for this to work.
Is there any other way?
