Search code examples
pythonpandasline-plot

Plot multiple rows of dataframe in pandas for specific columns


df

SKU  Comp Brand  Jan_Sales  Feb_Sales  Mar_sales Apr_sales  Dec_sales..
 A    AC   BA      122        100        50        200         300
 B    BC   BB      100        50         80        90          250
 C    CC   BC       40        30        100        10          11

and so on

Now I want a graph which will plot Jan sales, feb sales and so on till dec in one line for SKU A, Similarly one line on the same graph for SKU B and same way for SKU C.

I read few answers which say that I need to transpose my data. Something like below

 df.T. plot()

However my first column is SKU, and I want to plot based on that. Rest of the columns are numeric. So I want that on each line SKU Name should be mentioned. And plotting should be row wise

EDIT(added after receiving some answers as I am facing this issue in few other datasets):

lets say I dont want columns Company, brand etc, then what to do


Solution

  • Use set_index then transpose:

    df.set_index("SKU").T.plot()
    

    Output:

    enter image description here