JuanPablo JuanPablo - 2 months ago 6
Python Question

Pandas plot series with series names in one row

I have a csv file like this

date, name, value
2016-09-01, alice, 10
2016-09-02, alice, 11
2016-09-01, bob, 8
2016-09-02, bob, 14


With pandas can I plot as a line chart? Or must I change the structure of the file to something similar to

date, alice, bob
2016-09-01, 10, 8
2016-09-02, 11, 14

Answer

Pivot your dataframe to plot one curve per column:

df.pivot(index='date', columns='name').plot()
Comments