Skip to content

Commit 92dda6a

Browse files
committed
use _shared_docs
1 parent 8525253 commit 92dda6a

File tree

3 files changed

+58
-110
lines changed

3 files changed

+58
-110
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,65 +1385,11 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
13851385
if path_or_buf is None:
13861386
return formatter.path_or_buf.getvalue()
13871387

1388+
@Appender(_shared_docs['to_excel'] % _shared_doc_kwargs)
13881389
def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
13891390
float_format=None, columns=None, header=True, index=True,
13901391
index_label=None, startrow=0, startcol=0, engine=None,
13911392
merge_cells=True, encoding=None, inf_rep='inf', verbose=True):
1392-
"""
1393-
Write DataFrame to a excel sheet
1394-
1395-
Parameters
1396-
----------
1397-
excel_writer : string or ExcelWriter object
1398-
File path or existing ExcelWriter
1399-
sheet_name : string, default 'Sheet1'
1400-
Name of sheet which will contain DataFrame
1401-
na_rep : string, default ''
1402-
Missing data representation
1403-
float_format : string, default None
1404-
Format string for floating point numbers
1405-
columns : sequence, optional
1406-
Columns to write
1407-
header : boolean or list of string, default True
1408-
Write out column names. If a list of string is given it is
1409-
assumed to be aliases for the column names
1410-
index : boolean, default True
1411-
Write row names (index)
1412-
index_label : string or sequence, default None
1413-
Column label for index column(s) if desired. If None is given, and
1414-
`header` and `index` are True, then the index names are used. A
1415-
sequence should be given if the DataFrame uses MultiIndex.
1416-
startrow :
1417-
upper left cell row to dump data frame
1418-
startcol :
1419-
upper left cell column to dump data frame
1420-
engine : string, default None
1421-
write engine to use - you can also set this via the options
1422-
``io.excel.xlsx.writer``, ``io.excel.xls.writer``, and
1423-
``io.excel.xlsm.writer``.
1424-
merge_cells : boolean, default True
1425-
Write MultiIndex and Hierarchical Rows as merged cells.
1426-
encoding: string, default None
1427-
encoding of the resulting excel file. Only necessary for xlwt,
1428-
other writers support unicode natively.
1429-
inf_rep : string, default 'inf'
1430-
Representation for infinity (there is no native representation for
1431-
infinity in Excel)
1432-
1433-
Notes
1434-
-----
1435-
If passing an existing ExcelWriter object, then the sheet will be added
1436-
to the existing workbook. This can be used to save different
1437-
DataFrames to one workbook:
1438-
1439-
>>> writer = ExcelWriter('output.xlsx')
1440-
>>> df1.to_excel(writer,'Sheet1')
1441-
>>> df2.to_excel(writer,'Sheet2')
1442-
>>> writer.save()
1443-
1444-
For compatibility with to_csv, to_excel serializes lists and dicts to
1445-
strings before writing.
1446-
"""
14471393
from pandas.io.excel import ExcelWriter
14481394
need_save = False
14491395
if encoding is None:

pandas/core/generic.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,62 @@ def __setstate__(self, state):
10161016
# ----------------------------------------------------------------------
10171017
# I/O Methods
10181018

1019+
_shared_docs['to_excel'] = """
1020+
Write %(klass)s to a excel sheet
1021+
1022+
Parameters
1023+
----------
1024+
excel_writer : string or ExcelWriter object
1025+
File path or existing ExcelWriter
1026+
sheet_name : string, default 'Sheet1'
1027+
Name of sheet which will contain DataFrame
1028+
na_rep : string, default ''
1029+
Missing data representation
1030+
float_format : string, default None
1031+
Format string for floating point numbers
1032+
columns : sequence, optional
1033+
Columns to write
1034+
header : boolean or list of string, default True
1035+
Write out column names. If a list of string is given it is
1036+
assumed to be aliases for the column names
1037+
index : boolean, default True
1038+
Write row names (index)
1039+
index_label : string or sequence, default None
1040+
Column label for index column(s) if desired. If None is given, and
1041+
`header` and `index` are True, then the index names are used. A
1042+
sequence should be given if the DataFrame uses MultiIndex.
1043+
startrow :
1044+
upper left cell row to dump data frame
1045+
startcol :
1046+
upper left cell column to dump data frame
1047+
engine : string, default None
1048+
write engine to use - you can also set this via the options
1049+
``io.excel.xlsx.writer``, ``io.excel.xls.writer``, and
1050+
``io.excel.xlsm.writer``.
1051+
merge_cells : boolean, default True
1052+
Write MultiIndex and Hierarchical Rows as merged cells.
1053+
encoding: string, default None
1054+
encoding of the resulting excel file. Only necessary for xlwt,
1055+
other writers support unicode natively.
1056+
inf_rep : string, default 'inf'
1057+
Representation for infinity (there is no native representation for
1058+
infinity in Excel)
1059+
1060+
Notes
1061+
-----
1062+
If passing an existing ExcelWriter object, then the sheet will be added
1063+
to the existing workbook. This can be used to save different
1064+
DataFrames to one workbook:
1065+
1066+
>>> writer = ExcelWriter('output.xlsx')
1067+
>>> df1.to_excel(writer,'Sheet1')
1068+
>>> df2.to_excel(writer,'Sheet2')
1069+
>>> writer.save()
1070+
1071+
For compatibility with to_csv, to_excel serializes lists and dicts to
1072+
strings before writing.
1073+
"""
1074+
10191075
def to_json(self, path_or_buf=None, orient=None, date_format='epoch',
10201076
double_precision=10, force_ascii=True, date_unit='ms',
10211077
default_handler=None, lines=False):

pandas/core/series.py

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,65 +2619,11 @@ def to_csv(self, path=None, index=True, sep=",", na_rep='',
26192619
if path is None:
26202620
return result
26212621

2622+
@Appender(generic._shared_docs['to_excel'] % _shared_doc_kwargs)
26222623
def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
26232624
float_format=None, columns=None, header=True, index=True,
26242625
index_label=None, startrow=0, startcol=0, engine=None,
26252626
merge_cells=True, encoding=None, inf_rep='inf', verbose=True):
2626-
"""
2627-
Write Series to a excel sheet
2628-
2629-
Parameters
2630-
----------
2631-
excel_writer : string or ExcelWriter object
2632-
File path or existing ExcelWriter
2633-
sheet_name : string, default 'Sheet1'
2634-
Name of sheet which will contain DataFrame
2635-
na_rep : string, default ''
2636-
Missing data representation
2637-
float_format : string, default None
2638-
Format string for floating point numbers
2639-
columns : sequence, optional
2640-
Columns to write
2641-
header : boolean or list of string, default True
2642-
Write out column names. If a list of string is given it is
2643-
assumed to be aliases for the column names
2644-
index : boolean, default True
2645-
Write row names (index)
2646-
index_label : string or sequence, default None
2647-
Column label for index column(s) if desired. If None is given, and
2648-
`header` and `index` are True, then the index names are used. A
2649-
sequence should be given if the DataFrame uses MultiIndex.
2650-
startrow :
2651-
upper left cell row to dump data frame
2652-
startcol :
2653-
upper left cell column to dump data frame
2654-
engine : string, default None
2655-
write engine to use - you can also set this via the options
2656-
``io.excel.xlsx.writer``, ``io.excel.xls.writer``, and
2657-
``io.excel.xlsm.writer``.
2658-
merge_cells : boolean, default True
2659-
Write MultiIndex and Hierarchical Rows as merged cells.
2660-
encoding: string, default None
2661-
encoding of the resulting excel file. Only necessary for xlwt,
2662-
other writers support unicode natively.
2663-
inf_rep : string, default 'inf'
2664-
Representation for infinity (there is no native representation for
2665-
infinity in Excel)
2666-
2667-
Notes
2668-
-----
2669-
If passing an existing ExcelWriter object, then the sheet will be added
2670-
to the existing workbook. This can be used to save different
2671-
DataFrames to one workbook:
2672-
2673-
>>> writer = ExcelWriter('output.xlsx')
2674-
>>> s.to_excel(writer,'Sheet1')
2675-
>>> s.to_excel(writer,'Sheet2')
2676-
>>> writer.save()
2677-
2678-
For compatibility with to_csv, to_excel serializes lists and dicts to
2679-
strings before writing.
2680-
"""
26812627
df = self.to_frame()
26822628
df.to_excel(excel_writer=excel_writer, sheet_name=sheet_name,
26832629
na_rep=na_rep, float_format=float_format, columns=columns,

0 commit comments

Comments
 (0)