Making line chart of MIS using python and pandas

Viewed 34

I have a following dataframe with date as index

               Apples        Oranges       Strawberries
07-13-2020      1              5              10
07-14-2020      1              17              4

I have to make the line chart of above dataframe with number of fruits on the Y axis and dates on the x axis.

df.plot(x=df.index,y=["Apples","Oranges","Strawberries"],kind="line") is not working

how can I fix it?

3 Answers

Try converting your pandas index to datetime format and try again as below:

df.index = pd.to_datetime(df.index, format='%m-%d-%Y', errors='ignore')
df.plot(kind="line")

That's df.plot.line(). The index is automatically the x axis, and the columns are the groups.

Related