[英]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 ![]() |
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:我想创建一个结构,其中每个表的标题都得到一个 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.