Skip to content

Commit e218103

Browse files
committed
Add example usases of ExcelWriter cass
1 parent 172257a commit e218103

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pandas/io/excel.py

+28
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,19 @@ class ExcelWriter(object):
831831
832832
Examples
833833
--------
834+
Using ExcelWriter, some settings can be added.
835+
836+
Default usage.
837+
838+
>>> with ExcelWriter('path_to_file.xlsx') as writer:
839+
... df.to_excel(writer)
840+
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)
834847
835848
In order to write separate DataFrames to separate sheets
836849
in a single Excel file, one can pass an ExcelWriter.
@@ -839,6 +852,21 @@ class ExcelWriter(object):
839852
... df1.to_excel(writer, sheet_name='Sheet1')
840853
... df2.to_excel(writer, sheet_name='Sheet2')
841854
855+
You can set date format or datetime format
856+
857+
>>> with ExcelWriter('path_to_file.xlsx',
858+
date_format='YYYY-MM-DD',
859+
datetime_format='YYYY-MM-DD HH:MM:SS') as writer:
860+
... df.to_excel(writer)
861+
862+
It also supports append mode.
863+
864+
>>> with ExcelWriter('path_to_file.xlsx', mode='a') as writer:
865+
... df.to_excel(writer)
866+
867+
.. versionadded:: 0.24.0
868+
869+
842870
Attributes
843871
----------
844872
None

0 commit comments

Comments
 (0)