m3asmi
m3asmi

Reputation: 1262

how to plot groupped dataframe by date

I have a grouped by ['supplier','date_order'] as

                                    Amount
date_order  2011        2012            2013            2014            2015            2016            2017
supplier                            
fourni  0.000           1667750.000     4243250.000     2530000.000     2080000.000     1036200.000     1217400.000
supp_f  5289670.200     13076233.400    14199000.000    13181860.000    16177800.000    14525880.000    1346400.000
ifou    662250.000      2135750.000     2184150.000     1829800.000     1947880.000     1424820.000     1836100.000

How can get the plot of Amount of suppliers by years for each line in a line plot ?

Upvotes: 1

Views: 38

Answers (1)

jezrael
jezrael

Reputation: 862406

It seems you need select MultiIndex first for DataFrame and then DataFrame.plot:

df['Amount'].plot()

Or add Amount for remove MultiIndex in columns (change by your aggregate function):

df.groupby(['supplier','date_order'])['Amount'].sum().unstack(fill_value=0).plot()

EDIT:

For transpose use:

df['Amount'].T.plot()

Upvotes: 2

Related Questions