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

0

2 Answers 2

2

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

df.set_index('SKU').T.plot()
Sign up to request clarification or add additional context in comments.

Comments

1

Use set_index then transpose:

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

Output:

enter image description here

2 Comments

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
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().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.