我想合并 2 个数据帧,第一个是 dm.shape = (21184, 34)
,第二个是 po.shape = (21184, 6)
。我想合并它们,那么它将是 40 列。我这样写
dm = dm.merge(po, left_index=True, right_index=True)
然后是dm.shape = (4554, 40)
我的行数减少了。
P.s po
是 dm
数值数据的PolynomialFeatures
。
最佳答案
问题是索引值不同,因此将它们转换为两个 DataFrame 中的默认 RangeIndex
:
df = dm.reset_index(drop=True).merge(po.reset_index(drop=True),
left_index=True,
right_index=True)
解决方案 concat
- 默认情况下外连接,但如果两者的索引值相同:
df = pd.concat([dm.reset_index(drop=True), po.reset_index(drop=True)], axis=1)
关于python - 如何沿列轴连接两个具有不同索引的数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59962173/