Skip to content

Commit ba091c0

Browse files
Tomasz-Kluczkowskivictor
authored and
victor
committed
DOC: update the pandas.DataFrame.to_string docstring (pandas-dev#20173)
1 parent aceccc0 commit ba091c0

File tree

2 files changed

+89
-67
lines changed

2 files changed

+89
-67
lines changed

pandas/core/frame.py

+32-10
Original file line numberDiff line numberDiff line change
@@ -1966,14 +1966,35 @@ def to_parquet(self, fname, engine='auto', compression='snappy',
19661966
@Substitution(header='Write out the column names. If a list of strings '
19671967
'is given, it is assumed to be aliases for the '
19681968
'column names')
1969-
@Appender(fmt.docstring_to_string, indents=1)
1969+
@Substitution(shared_params=fmt.common_docstring,
1970+
returns=fmt.return_docstring)
19701971
def to_string(self, buf=None, columns=None, col_space=None, header=True,
19711972
index=True, na_rep='NaN', formatters=None, float_format=None,
19721973
sparsify=None, index_names=True, justify=None,
19731974
line_width=None, max_rows=None, max_cols=None,
19741975
show_dimensions=False):
19751976
"""
19761977
Render a DataFrame to a console-friendly tabular output.
1978+
1979+
%(shared_params)s
1980+
line_width : int, optional
1981+
Width to wrap a line in characters.
1982+
1983+
%(returns)s
1984+
1985+
See Also
1986+
--------
1987+
to_html : Convert DataFrame to HTML.
1988+
1989+
Examples
1990+
--------
1991+
>>> d = {'col1' : [1, 2, 3], 'col2' : [4, 5, 6]}
1992+
>>> df = pd.DataFrame(d)
1993+
>>> print(df.to_string())
1994+
col1 col2
1995+
0 1 4
1996+
1 2 5
1997+
2 3 6
19771998
"""
19781999

19792000
formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
@@ -1994,7 +2015,8 @@ def to_string(self, buf=None, columns=None, col_space=None, header=True,
19942015
return result
19952016

19962017
@Substitution(header='whether to print column labels, default True')
1997-
@Appender(fmt.docstring_to_string, indents=1)
2018+
@Substitution(shared_params=fmt.common_docstring,
2019+
returns=fmt.return_docstring)
19982020
def to_html(self, buf=None, columns=None, col_space=None, header=True,
19992021
index=True, na_rep='NaN', formatters=None, float_format=None,
20002022
sparsify=None, index_names=True, justify=None, bold_rows=True,
@@ -2004,20 +2026,15 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True,
20042026
"""
20052027
Render a DataFrame as an HTML table.
20062028
2007-
`to_html`-specific options:
2008-
2029+
%(shared_params)s
20092030
bold_rows : boolean, default True
20102031
Make the row labels bold in the output
20112032
classes : str or list or tuple, default None
20122033
CSS class(es) to apply to the resulting html table
20132034
escape : boolean, default True
20142035
Convert the characters <, >, and & to HTML-safe sequences.
2015-
max_rows : int, optional
2016-
Maximum number of rows to show before truncating. If None, show
2017-
all.
2018-
max_cols : int, optional
2019-
Maximum number of columns to show before truncating. If None, show
2020-
all.
2036+
notebook : {True, False}, default False
2037+
Whether the generated HTML is for IPython Notebook.
20212038
decimal : string, default '.'
20222039
Character recognized as decimal separator, e.g. ',' in Europe
20232040
@@ -2034,6 +2051,11 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True,
20342051
20352052
.. versionadded:: 0.23.0
20362053
2054+
%(returns)s
2055+
2056+
See Also
2057+
--------
2058+
to_string : Convert DataFrame to a string.
20372059
"""
20382060

20392061
if (justify is not None and

pandas/io/formats/format.py

+57-57
Original file line numberDiff line numberDiff line change
@@ -49,69 +49,69 @@
4949

5050

5151
common_docstring = """
52-
Parameters
53-
----------
54-
buf : StringIO-like, optional
55-
buffer to write to
56-
columns : sequence, optional
57-
the subset of columns to write; default None writes all columns
58-
col_space : int, optional
59-
the minimum width of each column
60-
header : bool, optional
61-
%(header)s
62-
index : bool, optional
63-
whether to print index (row) labels, default True
64-
na_rep : string, optional
65-
string representation of NAN to use, default 'NaN'
66-
formatters : list or dict of one-parameter functions, optional
67-
formatter functions to apply to columns' elements by position or name,
68-
default None. The result of each function must be a unicode string.
69-
List must be of length equal to the number of columns.
70-
float_format : one-parameter function, optional
71-
formatter function to apply to columns' elements if they are floats,
72-
default None. The result of this function must be a unicode string.
73-
sparsify : bool, optional
74-
Set to False for a DataFrame with a hierarchical index to print every
75-
multiindex key at each row, default True
76-
index_names : bool, optional
77-
Prints the names of the indexes, default True
78-
line_width : int, optional
79-
Width to wrap a line in characters, default no wrap
80-
table_id : str, optional
81-
id for the <table> element create by to_html
82-
83-
.. versionadded:: 0.23.0"""
52+
Parameters
53+
----------
54+
buf : StringIO-like, optional
55+
Buffer to write to.
56+
columns : sequence, optional, default None
57+
The subset of columns to write. Writes all columns by default.
58+
col_space : int, optional
59+
The minimum width of each column.
60+
header : bool, optional
61+
%(header)s.
62+
index : bool, optional, default True
63+
Whether to print index (row) labels.
64+
na_rep : str, optional, default 'NaN'
65+
String representation of NAN to use.
66+
formatters : list or dict of one-param. functions, optional
67+
Formatter functions to apply to columns' elements by position or
68+
name.
69+
The result of each function must be a unicode string.
70+
List must be of length equal to the number of columns.
71+
float_format : one-parameter function, optional, default None
72+
Formatter function to apply to columns' elements if they are
73+
floats. The result of this function must be a unicode string.
74+
sparsify : bool, optional, default True
75+
Set to False for a DataFrame with a hierarchical index to print
76+
every multiindex key at each row.
77+
index_names : bool, optional, default True
78+
Prints the names of the indexes.
79+
justify : str, default None
80+
How to justify the column labels. If None uses the option from
81+
the print configuration (controlled by set_option), 'right' out
82+
of the box. Valid values are
83+
84+
* left
85+
* right
86+
* center
87+
* justify
88+
* justify-all
89+
* start
90+
* end
91+
* inherit
92+
* match-parent
93+
* initial
94+
* unset.
95+
max_rows : int, optional
96+
Maximum number of rows to display in the console.
97+
max_cols : int, optional
98+
Maximum number of columns to display in the console.
99+
show_dimensions : bool, default False
100+
Display DataFrame dimensions (number of rows by number of columns).
101+
"""
84102

85103
_VALID_JUSTIFY_PARAMETERS = ("left", "right", "center", "justify",
86104
"justify-all", "start", "end", "inherit",
87105
"match-parent", "initial", "unset")
88106

89-
justify_docstring = """
90-
justify : str, default None
91-
How to justify the column labels. If None uses the option from
92-
the print configuration (controlled by set_option), 'right' out
93-
of the box. Valid values are
94-
95-
* left
96-
* right
97-
* center
98-
* justify
99-
* justify-all
100-
* start
101-
* end
102-
* inherit
103-
* match-parent
104-
* initial
105-
* unset
106-
"""
107-
108107
return_docstring = """
108+
Returns
109+
-------
110+
str (or unicode, depending on data and options)
111+
String representation of the dataframe.
112+
"""
109113

110-
Returns
111-
-------
112-
formatted : string (or unicode, depending on data and options)"""
113-
114-
docstring_to_string = common_docstring + justify_docstring + return_docstring
114+
docstring_to_string = common_docstring + return_docstring
115115

116116

117117
class CategoricalFormatter(object):
@@ -385,7 +385,7 @@ class DataFrameFormatter(TableFormatter):
385385
"""
386386

387387
__doc__ = __doc__ if __doc__ else ''
388-
__doc__ += common_docstring + justify_docstring + return_docstring
388+
__doc__ += common_docstring + return_docstring
389389

390390
def __init__(self, frame, buf=None, columns=None, col_space=None,
391391
header=True, index=True, na_rep='NaN', formatters=None,

0 commit comments

Comments
 (0)