I am trying to figure out how to pivot this table in Python.
example = {"ABC":{'2020-09':1.33,'2020-10':0.75,'2020-11':1.55},
"DEF":{'2020-09':1.22,'2020-10':1.75,'2020-11':2.73}}
df = pd.DataFrame(example)
df
Output of above code
I want it to pivot like this:
example = {"Date":['2020-09','2020-10','2020-11','2020-09','2020-10','2020-11'],
"Col1":['ABC','ABC','ABC','DEF','DEF','DEF'],
"Col2":[1.33,0.75,1.55,1.22,1.75,2.73]}
df = pd.DataFrame(example)
df
Output of above code
I created the two dictionaries to just illustrate the problem here. I have a much larger code that generates the first dataframe.
Could you please help me with transforming the first dataframe into the second one?
Thanks
Regards
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…