I have a dataframe with this format.
I have this dataframe:
id 2005-01-07 2008-01-07 ...
0 1Y 1.0 1.6
1 5Y 1.0 1.7
2 6Y 6.0 1.0
3 10Y 2.0 7.1
4 30Y 5.5 8.6
And I would like to convert it in:
id Date number
0 1Y 2005-01-07 1.0
1 1Y 2008-01-07 1.6
2 5Y 2005-01-07 1.0
3 5Y 2008-01-07 1.7
4 6Y 2005-01-07 6.0
5 6Y 2008-01-07 1.0
6 10Y 2005-01-07 2.0
7 10Y 2008-01-07 7.1
8 30Y 2005-01-07 5.5
9 30Y 2008-01-07 8.6
...
Is it possible to achieve this output in python? I tried to use transpose()
and replace
but can't reach the desired output
Answer by @mechanical_meat:
df = pd.melt(df, id_vars=['id'], var_name='Date', value_name='number')