How to plot line chart with lines from index?


I have a dataframe I’ve already aggregated averages for, which are the columns nr_1, nr_2, etc. They are grouped by a bin, which is also now the index. How do I create a line plot where the lines are the index, and the X axis is nr_1, nr_2, etc. basically nr_1, nr_2, etc. are months so I want those to be on x axis, but have the mean values as the y axis? I can figure out how to change the x/y axis, but not how to make the index the individual lines. Here is an excel picture of what I am trying to achieve and a snippet of the dataframe (this is in python by the way):

enter image description here

enter image description here

Asked By: New_to_Sas



Just transpose your dataframe:

import matplotlib.pyplot as plt

ax = df.T.plot()


enter image description here

Answered By: Corralien