0
votes

I want to plot multiple lines in one chart for the following dataset.

ID 01-02-2018 02-02-2018 03-02-2018 .... 29-03-2018 30-03-2018
ID_1 0.5 0.3 0.6 ---- 0.4 0.5
ID_2 0.3 0.2 0.5 ---- 0.5 0.3
ID_3 0.4 0.6 0.4 ---- 0.3 0.4
ID_4 0.6 0.7 0.4 ---- 0.2 0.2
ID_5 0.8 0.4 0.3 ---- 0.6 0.8

In my plot, Dates should be displayed on the X-axis and a single graph should contain the line chart for ID1 to ID5. I tried different solutions but did not get the desired plot.

1

1 Answers

2
votes

You just have to do a transpose of you dataframe:

data={"01-02-2018":[0.5,0.7,0.8,0.9,1],"02-02-2018":[1,1.2,1.8,3,2],
    "03-02-2018":[4,3.2,0.8,1,6],"04-02-2018":[1,1.2,1.8,3,2]}

df=pd.DataFrame(data)

dft=df.transpose()
dft.plot.line()
plt.show()

result: enter image description here