2

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.

How would I preserve the same conciseness, and set the column names?

1
  • How do you generate the list of series objects? Because you could also ensure that there the series name is set to the function name, then this name will be used as column name after concatting. Commented Dec 12, 2015 at 15:24

2 Answers 2

2

IIUC, given your concat dataframe df you can:

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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__]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.