简体   繁体   English

熊猫自动从具有列名称的系列列表中创建数据框

[英]pandas automatically create dataframe from list of series with column names

I have a list of pandas series objects. 我有一个熊猫系列对象列表。 I have a list of functions that generate them. 我列出了生成它们的函数。 How do I create a dataframe of the objects with the column names being the names of the functions that created the objects? 如何使用列名作为创建对象的函数的名称来创建对象的数据框?

So, to create the regular dataframe, I've got: 因此,要创建常规数据框,我需要:

pandas.concat([list of series objects],axis=1,join='inner')

But I don't currently have a way to insert all the functionA.__name__, functionB.__name__, etc. as column names in the dataframe. 但是我目前functionA.__name__, functionB.__name__, etc.无法将所有functionA.__name__, functionB.__name__, etc.作为列名插入数据functionA.__name__, functionB.__name__, etc.

How would I preserve the same conciseness, and set the column names? 如何保持相同的简洁性并设置列名?

You can set the column names in a second step: 您可以在第二步中设置列名称:

df = pandas.concat([list of series objects],axis=1,join='inner')
df.columns = [functionA.__name__, functionB.__name__]

IIUC, given your concat dataframe df you can: IIUC,鉴于您的concat数据框df您可以:

df = pandas.concat([list of series objects],axis=1,join='inner')

and then assign the column names as a list of functions names: 然后将列名称分配为函数名称列表:

df.columns = [functionA.__name__, functionB.__name__, etc.]

Hope that helps. 希望能有所帮助。

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

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