Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: DataFrame.apply can return several columns #5299

Closed
ohadle opened this issue Oct 23, 2013 · 6 comments
Closed

doc: DataFrame.apply can return several columns #5299

ohadle opened this issue Oct 23, 2013 · 6 comments

Comments

@ohadle
Copy link

ohadle commented Oct 23, 2013

Might be worth mentioning in the docs that if "func" returns a Series, the result is a DataFrame.
It took me a while to figure this out (tried with tuples and a dict).

@ohadle ohadle closed this as completed Oct 23, 2013
@ohadle ohadle reopened this Oct 23, 2013
@jtratner
Copy link
Contributor

If you wanted to operate rows wise, you could also select two columns firsf (df[[a,b]]) and then apply off of that with a function that returns 2 - tuples / two element lists?

If you want to create a new DataFrame of a different size, you can use zip or izip in a list comprehension to the DataFrame constructor.

DataFrame([my_apply_func(a,  b) for a, b in zip(df[a], df[b])], columns=['a', 'b', 'c'])

@jtratner
Copy link
Contributor

And I guess the title of this changed since I posted this... Whoops.

@jreback
Copy link
Contributor

jreback commented Oct 23, 2013

@ohadle this has been in the docs for a while: http://pandas.pydata.org/pandas-docs/dev/groupby.html#flexible-apply

@ohadle
Copy link
Author

ohadle commented Oct 23, 2013

Sorry, I kept looking over here
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html
and missed that part of the docs. Thanks for the pointers.
Might still be worth adding to the API docs?

@jreback
Copy link
Contributor

jreback commented Oct 23, 2013

you mean a reference to the apply section...sure that would be nice, Pull-Request?

@jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche modified the milestones: Next Major Release, 0.23.0 Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants