python - Plotting multiple time series after a groupby in pandas -


suppose made groupby on valgdata dataframe below:

grouped_valgdata = valgdata.groupby(['news_site','dato_uden_tid']).mean() 

now this:

                                  sentiment news_site          dato_uden_tid            dr.dk              2015-06-15     54.777183                    2015-06-16     54.703167                    2015-06-17     54.948775                    2015-06-18     54.424881                    2015-06-19     53.290554 eb.dk              2015-06-15     53.279251                    2015-06-16     53.285643                    2015-06-17     53.558753                    2015-06-18     52.854750                    2015-06-19     54.415988 jp.dk              2015-06-15     56.590428                    2015-06-16     55.313752                    2015-06-17     53.771377                    2015-06-18     53.218408                    2015-06-19     54.392638 pol.dk             2015-06-15     54.759532                    2015-06-16     55.182641                    2015-06-17     55.001800                    2015-06-18     56.004326                    2015-06-19     54.649052 

now want make timeseries each of news_site, dato_uden_tid on x axis , sentiment on y axis.

what best , easiest way accomplish that?

thank you!

(am bit amused, question caught me doing exact same thing.)

you like

valgdata\     .groupby([valgdata.dato_uden_tid.name, valgdata.news_site.name])\     .mean()\     .unstack() 

which

  • reverse groupby

  • unstack new sites columns

to plot, previous snippet followed .plot():

valgdata\     .groupby([valgdata.dato_uden_tid.name, valgdata.news_site.name])\     .mean()\     .unstack()\     .plot() 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -