-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: add to_frame method to Series #5164
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
Conversation
assert_almost_equal(rs, xp) | ||
|
||
df = self.ts.to_dataframe(name = 'rs') | ||
df['xp'] = self.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use assert_frame_equal
to compare the result vs the expected frame. pls add a test if name is passed in to_dataframe
but name is different on the Series.
pls also add a release notes entry (you can reference this PR for the issue number), enhancements section. also add to the docs section in api. and a 1-liner in v0.13.0.txt |
""" | ||
from pandas.core.frame import DataFrame | ||
if name is None: | ||
df = DataFrame(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this around a bit. The passed name should substitute for the series name (if it has one). and need a correspodning test for this as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name = name if name is not None else self.name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update with feedback. Thanks.
On Wednesday, October 9, 2013, jreback wrote:
In pandas/core/series.py:
- def to_dataframe(self, name=None):
"""
Convert Series to DataFrame
Parameters
name : object, default None
The name of the column corresponding to the Series values
Returns
data_frame : DataFrame
"""
from pandas.core.frame import DataFrame
if name is None:
df = DataFrame(self)
name = name if name is not None else self.name
—
Reply to this email directly or view it on GitHubhttps://github.com//pull/5164/files#r6869332
.
David Rasch
[email protected]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from above, I'm not sure that
name = name if name is not None else self.name
will work when self.name = None
You end up with 'None' as the column index instead of 0.
I'm adding a test for this case too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes if name is none then just do Dataframe(self)
the name parameter that u r passing should override the name of the series I think
pls change the name of the method to |
See updated commit. Thanks for all the feedback. @jreback let me know if the tests don't address the case you're concerned about |
"also add to the docs section in api." how do I do this? |
edit docs/source/api.rst just like other files |
on another note, how do I generate the docs for testing? |
make doc |
Updated commit should include docs update. |
just needs the name changed to |
@drasch thanks! |
doh, I just added the release.rst entry |
no worries I added on the merge |
Adding a method to Series to promote it to a DataFrame. I've wished this existed so that when a method returns a series, and you could easily promote it to a DataFrame so that it's easier to add columns to it.