Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multi line time series pandas

I am trying to plot a multi line graph from pandas in python. I need three lines (positive, negative, neutral) and their number of occurrences during time. On the x-axis I would have the time, on the y- axis I would have the number of occurrences and I would have three lines in one graph. If there is no occurrence then it would be automatically zero (for example in th etable there is no occurrence for "negative" so in the graph the point would be zero). I am attaching the table that I would need to turn into graph.

d = datapandas.groupby(["date","classification"]).size()

enter image description here

The most left column is the number of occurrence of the classification during the date. I could not find any easy way to plot this kind of graph.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have just to unstack the classification index and plot the graph:

d.unstack('classification').fillna(0).plot()

Note: you can avoid groupby by using value_counts:

d = datapandas.value_counts(['date', 'classification'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading