Hi I have a DataFrame like this It is a table of a sales information with row index of product brand and column index of Price,Week and Timestamp.
timeperiod = pd.date_range(start='4/15/2019', periods=3,dtype='datetime64[ns]', freq='D')
df = pd.DataFrame({'Price':[[2000,2000,2000],[1000,1000,1000]],'Week':[[0,0,1],[0,0,1]],
'Timestamp': [timeperiod,timeperiod]},index = ['Apple','Huawei'])
The output of the code above is:
Price Timestamp Week
Apple [2000, 2000, 2000] DatetimeIndex(['2019-04-15', '2019-04-16', '20... [0, 0, 1]
Huawei [1000, 1000, 1000] DatetimeIndex(['2019-04-15', '2019-04-16', '20... [0, 0, 1]
Now I want to flatten the dataframe to three columns [Price,Timestamp and Week ]with index of a series of number [0,1,2] (since i got 3 element in list), and store in Two dataframes,which were named after the original dataframe index, Apple and Huawei.
so the outcome should be
Apple = pd.DataFrame({'Price':[2000,2000,2000],'Week':[0,0,1],
'Timestamp': timeperiod})
Huawei = pd.DataFrame({'Price':[1000,1000,1000],'Week':[0,0,1],
'Timestamp': timeperiod})
Apple:
Price Timestamp Week
0 2000 2019-04-15 0
1 2000 2019-04-16 0
2 2000 2019-04-17 1
Huawei:
Price Timestamp Week
0 1000 2019-04-15 0
1 1000 2019-04-16 0
2 1000 2019-04-17 1