【问题标题】:concatenate dataframe with dataframe from list将数据框与列表中的数据框连接起来
【发布时间】:2022-12-12 14:04:31
【问题描述】:

我想将数据帧 (df) 与存储在数据帧列表中的另一个数据帧连接起来。

dflist = [df1, df2, df3]

我想要的是像下面这样的数据框

new_dflist = [df+df1, df+df2, df+df3]

new_dflist=[]
for n in dflist:
    new_dflist.append(pd.concat(df, dflist[n]))

但我得到了错误, 类型错误:列表索引必须是整数或切片,而不是 DataFrame

我也试过 enumerate 但我得到了错误, 类型错误:列表索引必须是整数或切片,而不是元组

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    尝试这个:

    new_dflist=[]
    for n in dflist:
        new_dflist.append(pd.concat(df, n))
    

    n 是一个数据框,您正试图将其放入列表索引中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      • 2019-03-13
      • 2022-08-20
      • 2021-02-07
      • 2019-04-17
      • 2019-12-03
      相关资源
      最近更新 更多