2

I have a few dataframes and I would like to concat them in a special manor.

We have 2 tables:

A B
1 2
3 4
C D
"Cat" "Dog"
"Dino" "Fish"

I would like to create a structure where headers from each table are getting one header like this:

enter image description here

How is it done with Pandas?

Thank you.

1 Answer 1

3

If df1 is your Table1 and df2 is Table2, then:

out = pd.concat({"Numbers": df1, "Center": df2}, axis=1)
print(out)

Prints:

  Numbers    Center      
        A  B      C     D
0       1  2    Cat   Dog
1       3  4   Dino  Fish
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.