简体   繁体   English

Python Pandas Dataframe 中的数据帧

[英]Python Pandas Dataframes in Dataframe

I have a few dataframes and I would like to concat them in a special manor.我有几个数据框,我想将它们连接到一个特殊的庄园中。

We have 2 tables:我们有 2 个表:

A一种 B
1 1个 2 2个
3 3个 4 4个
C C D
"Cat" “猫” "Dog" “狗”
"Dino" “恐龙” "Fish" “鱼”

I would like to create a structure where headers from each table are getting one header like this:我想创建一个结构,其中每个表的标题都得到一个 header,如下所示:

在此处输入图像描述

How is it done with Pandas? Pandas 是怎么做到的?

Thank you.谢谢你。

If df1 is your Table1 and df2 is Table2, then:如果df1是您的 Table1 而df2是 Table2,那么:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM