I have the following dataframe (sim_2005):
Date ELEM1 ELEM2 ... ELEM1133
2005-01-01 0.021 2.455 ... 345.2
2005-01-02 0.321 2.331 ... 355.1
...
A possibly simpler solution still using .melt()
is to pull your date index out into a column with .reset_index()
first:
sim_2005_melted = pd.melt(sim_2005.reset_index(), id_vars=sim_2005.index.name, value_vars=list(sim_2005.columns.values), var_name='ELEM', value_name='Q_sim')
You get the same result with .stack()
but this way is a bit more flexible if you want all the extra melty goodness.