I need help reshaping a DataFrame that i got from a csv file.
In this file I have the first column as ID and then 97 columns that represent sale units of 4 products during time.
the data is like
id p1_201501 p1_201502 ...... p1_201812 p2_201501..... p2_2018012 p3_..
x12 125 12 ...... 06 500 ..... 14 2...
nz15 250 16 ...... 600 423 ..... 312 56...
....
The Id represent the area in which the product is sold. And I have 700 rows (i.e 700 df['id'].nunique() ) And so I need to find the yearly sales trend of a given product. So i thought the solution is to change the dataframe in order to have years as rows and the quantity for each product (p1, p2, p3)
Something like:
id date p1 p2 p3
x12 201501 12 500 32
201502 ....
201503 ....
....
201812 .....
nz15 201501 .....
201502 .....
.....
201812 .....
But I don't know if it is the right choice to find the saled trend in this case and if so How to change the first dataframe to be like the second I know some about pivot reshape. But I can't find how to do it and how to keep the id (the area in which the product is sold)
Any help please?