The Problem
I have a Pandas DataFrame with the current layout of data:
I simply want to convert it to a Pandas DataFrame that looks like:
Date Value
0 01-Jan-1914 2.0
1 01-Feb-1914 1.0
2 01-Mar-1914 1.0
... ... ...
108 01-Jan-2024 3.1
109 01-Feb-2024 3.2
110 01-Mar-2024 3.5
A new DataFrame with a single column for the date and another for the corresponding value.
Attempts So Far
I found the pd.DataFrame.stack() method that, once I drop the Year column with DataFrame.drop(columns=["Year"])
, got me most of the way there.
Though this gives me a pd.Series
object with a multi-index that I’m struggling to work with to get the final date output.
The temptation is to iterate through the rows but this would be rather slow and I imagine there already exists a Pandas or NumPy method that can achieve the desired output I need.
Thanks in advance for any help!