0

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

noob
  • 3,601
  • 6
  • 27
  • 73

2 Answers2

2

Use DataFrame.set_index for convert SKU to index and then tranpose:

df.set_index('SKU').T.plot()
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
1

Use set_index then transpose:

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

Output:

enter image description here

Chris
  • 29,127
  • 3
  • 28
  • 51
  • if I want to include only few columns say in my graph then what to do? Lets say there are columns like company and brand etc of SKU which I dont want to include in my graph, then what to do ? How to include only specific columns – noob Jan 30 '20 at 08:58
  • 1
    If you were to, say, use only `A` and `B`, try using `loc`: `df.set_index("SKU").loc[["A","B"]].T.plot()`. Or, if you want to _filter out_ `C`, use `drop`: `df.set_index("SKU").drop(["C"]).T.plot()`. – Chris Jan 30 '20 at 09:00