Skip to content

Commit b2f1880

Browse files
committed
Align with to_excel method
1 parent e218103 commit b2f1880

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

pandas/core/generic.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -1924,11 +1924,25 @@ def _repr_latex_(self):
19241924
If you wish to write to more than one sheet in the workbook, it is
19251925
necessary to specify an ExcelWriter object:
19261926
1927-
>>> writer = pd.ExcelWriter('output2.xlsx', engine='xlsxwriter')
1928-
>>> df1.to_excel(writer, sheet_name='Sheet1')
1929-
>>> df2 = df1.copy()
1930-
>>> df2.to_excel(writer, sheet_name='Sheet2')
1931-
>>> writer.save()
1927+
>>> with ExcelWriter('output.xlsx') as writer:
1928+
... df1.to_excel(writer, sheet_name='Sheet_name_1')
1929+
... df2.to_excel(writer, sheet_name='Sheet_name_2')
1930+
1931+
If you want to set engine that can manipulate Excel,
1932+
pass keyword argument named engine. Actually
1933+
engine is automatically chosen by file extension:
1934+
1935+
>>> df1.to_excel('output1.xlsx', engine='xlsxwriter')
1936+
>>> with ExcelWriter('output2.xlsx', engine='openpyxl') as writer:
1937+
... df2.to_excel(writer)
1938+
1939+
You can set date format or datetime format:
1940+
1941+
>>> with ExcelWriter('path_to_file.xlsx',
1942+
date_format='YYYY-MM-DD',
1943+
datetime_format='YYYY-MM-DD HH:MM:SS') as writer:
1944+
... df.to_excel(writer)
1945+
19321946
"""
19331947

19341948
def to_json(self, path_or_buf=None, orient=None, date_format=None,

pandas/io/excel.py

+5-16
Original file line numberDiff line numberDiff line change
@@ -824,49 +824,38 @@ class ExcelWriter(object):
824824
825825
Notes
826826
-----
827-
None of methods and properties are considered public.
827+
None of the methods and properties are considered public.
828828
829829
For compatibility with CSV writers, ExcelWriter serializes lists
830830
and dicts to strings before writing.
831831
832832
Examples
833833
--------
834-
Using ExcelWriter, some settings can be added.
835-
836-
Default usage.
834+
Default usage:
837835
838836
>>> with ExcelWriter('path_to_file.xlsx') as writer:
839837
... df.to_excel(writer)
840838
841-
If you want to set engine that can manipulate Excel,
842-
pass keyword argument named engine. Actually
843-
engine is automatically chosen by file extension.
844-
845-
>>> with ExcelWriter('path_to_file.xlsx', engine='openpyxl') as writer:
846-
... df.to_excel(writer)
847-
848-
In order to write separate DataFrames to separate sheets
849-
in a single Excel file, one can pass an ExcelWriter.
839+
To write to separate sheets in a single file:
850840
851841
>>> with ExcelWriter('path_to_file.xlsx') as writer:
852842
... df1.to_excel(writer, sheet_name='Sheet1')
853843
... df2.to_excel(writer, sheet_name='Sheet2')
854844
855-
You can set date format or datetime format
845+
You can set date format or datetime format:
856846
857847
>>> with ExcelWriter('path_to_file.xlsx',
858848
date_format='YYYY-MM-DD',
859849
datetime_format='YYYY-MM-DD HH:MM:SS') as writer:
860850
... df.to_excel(writer)
861851
862-
It also supports append mode.
852+
You can also append to an existing Excel file:
863853
864854
>>> with ExcelWriter('path_to_file.xlsx', mode='a') as writer:
865855
... df.to_excel(writer)
866856
867857
.. versionadded:: 0.24.0
868858
869-
870859
Attributes
871860
----------
872861
None

0 commit comments

Comments
 (0)