I have the following DataFrame:
import pandas as pd
import numpy as np
dates = pd.date_range('20130101',periods=6)
df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))
which is:
out[]:df
A B C D
2013-01-01 0.849638 0.163683 -0.422279 -0.981363
2013-01-02 -0.828562 -0.726762 -0.154431 1.695164
2013-01-03 1.668989 1.057559 -0.958682 -1.443136
2013-01-04 -3.386432 0.115499 -2.095343 -1.887334
2013-01-05 1.595712 0.270327 -0.532860 -0.690501
2013-01-06 -1.734169 0.574431 -0.982097 1.092113
I stacked the dataframe with purpose and it appears as below:
2013-01-01 A 0.849638
B 0.163683
C -0.422279
D -0.981363
2013-01-02 A -0.828562
B -0.726762
C -0.154431
D 1.695164
2013-01-03 A 1.668989
B 1.057559
C -0.958682
D -1.443136
2013-01-04 A -3.386432
B 0.115499
C -2.095343
D -1.887334
2013-01-05 A 1.595712
B 0.270327
C -0.532860
D -0.690501
2013-01-06 A -1.734169
B 0.574431
C -0.982097
D 1.092113
dtype: float64
I wish to have the dates printed in all the rows instead of having merged together. I want to have something like this:
2013-01-01 A 0.849638
2013-01-01 B 0.163683
2013-01-01 C -0.422279
2013-01-01 D -0.981363
.......
.......
2013-01-06 A -1.734169
2013-01-06 B 0.574431
2013-01-06 C -0.982097
2013-01-06 D 1.092113
dtype: float64
Can anyone please help me to achieve this goal. Thank you.