Home > database >  How to create a multi-indexed DataFrame using Python
How to create a multi-indexed DataFrame using Python

Time:06-16

I need to create a multi-indexed table of data using DataFrames in Python.

Basically, I want the left index to be a timestamp (it's in date-time), and the following data to be in columns indexed by date. [I.e. I have a timestamp and two columns of data stored in this DataFrame, say DF0.]
1

Say each of the DataFrames (i.e. DF0) has an ID attached to it. That would be the secondary index overhanging above the column titles.

[This is the table after merging two DataFrames, say DF0 and DF1.]
2 This is the ideal output but it needs a secondary index that I would be able to assign, we can say 5 and 6 for this example.

[The ideal output is this picture.]
3

Thank you in advance for your time and effort.

CodePudding user response:

Try using:

pd.concat([df1,df2], keys=['ID1','ID2'], axis=1)
  • Related