简体   繁体   English

动态 append 数据到 pandas dataframe

[英]dynamically append data to pandas dataframe

I'm trying to build my code as general as possible.我正在尝试尽可能通用地构建我的代码。

Part of my code is to build couple of data frames (which latter would be joined to one 'master' data frame), however each of this partial data frames contains variable number of columns.我的部分代码是构建几个数据框(后者将连接到一个“主”数据框),但是每个部分数据框都包含可变数量的列。

I'm passing to my function a list which contains the name of the columns names.我正在向我的 function 传递一个包含列名称的列表。 How can I make this as general as possible.我怎样才能使它尽可能普遍。 If I'll pass to my function any of list1 or list2如果我将传递给我的 function list1 或 list2 中的任何一个

list1 = ['a.element1', 'a.element2']
list2 = ['b.elementA', 'b.elementB']

Eventual df1 shall contain columns element1 and element2 and df contain columns elementA and elementB最终 df1 应包含列element1 and element2并且 df 包含列elementA and elementB

df1 = myFunciton(list1, data1)
df2 = myFunciton(list2, data2)

Do you mean this?你是这个意思吗?

df_master= df1.append([df2, df3, .., dfn])

Otherwise, please give a minimal reproducible example of what you mean and want to achieve.否则,请给出您的意思和想要实现的最小可重复示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM