Search code examples
pythonpandasplotlineline-plot

Plot line plot using rows of dataframe and include specific columns by position/number in python pandas


df

SKU   A    B  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 want to drop columns A and B. I know how to do that using column name, but how can i do that using column number/position

df.set_index("SKU").drop(['A','B']).T.plot()

How to drop A and B using their position 1 and 2 in this case


Solution

  • Add DataFrame.iloc for remove first and second columns, here A and B:

    df.set_index("SKU").iloc[:, 2:].T.plot()