1

These are my 3 current dataframes with same columns -

TP FP     TP FP     TP FP
 1  3      8 11      4  7
22 14     10 13      0 19 

Here's how I want it in a single dataframe-

OCT-19    NOV-19    DEC-19
TP  FP    TP  FP    TP FP
 1   3     8  11     4  7
22  14    10  13     0 19 

1 Answer 1

1
headers = pd.MultiIndex.from_product([["OCT-19"], ["TP", "FP"]])
df1 = pd.DataFrame([[1, 3], [22, 14]], columns=headers)

Just use MultiIndex.from_product() to specify the headers you want for your columns. Then you can pass these headers into the columns of your dataframe.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.