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:
How is it done with Pandas?
Thank you.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.