I have a DataFrame like the below one, with identifiers as a column on top of an existing dateindex.
pd.DataFrame(index = [pd.to_datetime('2021-01-01'), pd.to_datetime('2021-01-01'),pd.to_datetime('2021-01-02'),pd.to_datetime('2021-01-02'), pd.to_datetime('2021-01-03'),pd.to_datetime('2021-01-03')], columns=['id','A', 'B'], data=[['foo',1,5],['bar',8,12],['foo',7,1], ['bar',5,1], ['foo',4,3],['bar',7,1]])
Out[6]:
id A B
2021-01-01 foo 1 5
2021-01-01 bar 8 12
2021-01-02 foo 7 1
2021-01-02 bar 5 1
2021-01-03 foo 4 3
2021-01-03 bar 7 1
My goal is to create a new sub-dataframes for each of the columns (A and B) except id, with dateIndex as single Index, and id (foo, bar) as column names. The expected output is shown below:
A
Out[9]:
foo bar
2021-01-01 1 8
2021-01-02 7 5
2021-01-03 4 7
B
Out[11]:
foo bar
2021-01-01 5 12
2021-01-02 1 1
2021-01-03 3 1