python - 熊猫如何在没有键的情况下组合两个表
问题描述
我想要的很简单,但是pandas对我来说很困惑,我只想合并两个表
表格1:
Column 1,Column 2
Value1, Value1
Value2, Value2
表 2:
Column 3,Column 4
Value1, Value1
Value2, Value2
我想要的是
Column 1,Column 2,Column 3,Column 4
Value1, Value1, Value1, Value1
Value2, Value2, Value2, Value2
注意:没有相同的列,没有键,只是逐行组合,所以我认为“合并”不起作用
解决方案
假设您有以下数据框/表:
df1 = pd.DataFrame.from_dict({'a': [1,2,3], 'b': [4,5,6]})
a b
0 1 4
1 2 5
2 3 6
df2 = pd.DataFrame.from_dict({'c': [7,8,9], 'd': [10,11,11]})
c d
0 7 10
1 8 11
2 9 11
使用以下代码行,您可以连接它们:
new = pd.concat([df1, df2], axis=1)
输出:
a b c d
0 1 4 7 10
1 2 5 8 11
2 3 6 9 11
推荐阅读
- javascript - 如何在 React JS 中为文本设置颜色
- html - CSS:没有 100% 高度/宽度的滚动条
- google-cloud-platform - GCP是否为vm实例分配子域名?
- maven - Sonarqube [http://loalhost:9000/batch/index] 无效:[404] 错误
- c# - 动画后世界位置变化 - Unity
- r - 将数据框中的值分配给R中的矩阵的最快方法?
- sql - 将 BULK COLLECT 与 rownum 一起使用
- javascript - 带有折叠的动态引导列表无法正常工作
- python - 比较来自两个不同数据帧的列元素,其中条件基于 pandas 中的函数
- mysql - 如何避免 GROUP_CONCAT() 行乘以我的 SUM()