-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Pandas Series provide to_excel method #14780
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
ENH: Pandas Series provide to_excel method #14780
Conversation
strings before writing. | ||
""" | ||
from pandas.core.frame import DataFrame | ||
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.
use .to_frame
.
""" | ||
from pandas.core.frame import DataFrame | ||
df = DataFrame(self) | ||
df.to_excel(excel_writer, sheet_name, na_rep, |
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.
pls use keyword args as locations may be changed.
na_rep=na_rep, float_format=float_format, columns=columns, | ||
header=header, index=index, index_label=index_label, | ||
startrow=startrow, startcol=startcol, engine=engine, | ||
merge_cells=merge_cells, encoding=encoding, |
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 shared docs here to avoid repeating everything
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.
Could you show me an example?
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.
look for shared_doc
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.
Should this shared docstring be in pandas/io/excel.py
or somewhere else?
@@ -2619,6 +2619,19 @@ def to_csv(self, path=None, index=True, sep=",", na_rep='', | |||
if path is None: | |||
return result | |||
|
|||
@Appender(generic._shared_docs['to_excel'] % _shared_doc_kwargs) | |||
def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='', |
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.
add to the doc-string a versionadded tag (0.20.)
this prob needs to be added to |
Could you retrigger this job ? Thanks |
@scls19fr The job fails because of a lint error. pls fix. |
Current coverage is 85.27% (diff: 100%)@@ master #14780 diff @@
==========================================
Files 144 144
Lines 50946 50953 +7
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 43445 43452 +7
Misses 7501 7501
Partials 0 0
|
fcaa86b
to
df02b00
Compare
Thanks @sinhrks I didn't noticed because that's only for 1 job. |
_shared_docs['to_excel'] = """ | ||
Write %(klass)s to a excel sheet | ||
|
||
.. versionadded:: 0.20.0 |
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 is not the case for DataFrame. You can add it separately for series with _shared_doc_kwargs
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.
@jorisvandenbossche how will you name this key in _shared_doc_kwargs
?
What value will you put? .. versionadded:: 0.20.0
or 0.20.0
?
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.
The first one, as for DataFrame.excel there should be no versionadded
@@ -49,7 +49,7 @@ Other enhancements | |||
^^^^^^^^^^^^^^^^^^ | |||
|
|||
- ``pd.read_excel`` now preserves sheet order when using ``sheetname=None`` (:issue:`9930`) | |||
|
|||
- ``Series`` provides a ``to_excel`` method to output Excel files (:issue:`8825`) |
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.
Series has gained a .to_excel
method, to output Excel files, similar to DataFrame.to_excel
@@ -105,7 +105,8 @@ | |||
axes_single_arg="{0 or 'index', 1 or 'columns'}", | |||
optional_by=""" | |||
by : str or list of str | |||
Name or list of names which refer to the axis items.""") | |||
Name or list of names which refer to the axis items.""", |
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.
@jorisvandenbossche any better way to do this?
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 think this is fine (given our current way of doing this with _shared_doc_kwargs
. This could maybe get an overhaul, but that is another issue :-))
pls rebase and push again |
8f5e162
to
4353531
Compare
dc2c5ca
to
0ab4876
Compare
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.
Looks good, small comment regarding newlines in the resulting docstring
Write %(klass)s to a excel sheet | ||
|
||
%(versionadded_to_excel)s | ||
|
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.
Can you remove the blank lines before and after the versionadded here? And include the newlines in the versionadded_to_excel
arg for Series. Because otherwise for DataFrame.to_excel, you would get three blank lines instead of one here.
@@ -105,7 +105,8 @@ | |||
axes_single_arg="{0 or 'index', 1 or 'columns'}", | |||
optional_by=""" | |||
by : str or list of str | |||
Name or list of names which refer to the axis items.""") | |||
Name or list of names which refer to the axis items.""", |
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 think this is fine (given our current way of doing this with _shared_doc_kwargs
. This could maybe get an overhaul, but that is another issue :-))
@scls19fr Thanks a lot! |
git diff upstream/master | flake8 --diff