【问题标题】:Combining dataframes without knowing the amount of columns在不知道列数的情况下组合数据框
【发布时间】:2020-01-18 09:21:45
【问题描述】:

我有Dataframe1,即:

A          B
apple      tree
bed        house
triangle   cheese

和数据框 2:

C      D
dog    rabbit
cat    cheese
fish   gold

有没有办法像下面这样将它们连接在一起,而不知道 Dataframe 2 中的列是什么,或者它们有多少?

A          B         C       D       
apple      tree      dog     rabbit
bed        house     cat     cheese
triangle   cheese    fish    gold

【问题讨论】:

标签: python dataframe


【解决方案1】:

如果它们的行数相同,您可以这样做

df = pd.concat([df1, df2], axis=1)

A          B         C       D       
apple      tree      dog     rabbit
bed        house     cat     cheese
triangle   cheese    fish    gold

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 2015-05-17
    • 2016-12-03
    • 1970-01-01
    • 2018-11-16
    相关资源
    最近更新 更多