Skip to content

DOC: update the pandas.DataFrame.to_string docstring #20173

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

Merged
merged 10 commits into from
Jul 10, 2018
Merged
22 changes: 20 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,11 +1721,29 @@ def to_parquet(self, fname, engine='auto', compression='snappy',
@Appender(fmt.docstring_to_string, indents=1)
def to_string(self, buf=None, columns=None, col_space=None, header=True,
index=True, na_rep='NaN', formatters=None, float_format=None,
sparsify=None, index_names=True, justify=None,
sparsify=None, index_names=True,
line_width=None, max_rows=None, max_cols=None,
show_dimensions=False):
show_dimensions=False, justify=None):
"""
Render a DataFrame to a console-friendly tabular output.

Convert DataFrame object into a string (or unicode) representation
which can be shown in command line interface.

See Also
--------
pandas.DataFrame.to_html
Convert dataframe to a html file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method explanation should be after the method itself separated by space, colon (:) and space. A second line is allowed if the explanation doesn't fit in one line.


Examples
--------
>>> d = {'col1' : [1, 2, 3], 'col2' : [4, 5, 6]}
>>> df = pd.DataFrame(d)
>>> print(df.to_string())
col1 col2
0 1 4
1 2 5
2 3 6
"""

formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
Expand Down
59 changes: 31 additions & 28 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,38 @@
Parameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters should go before the See Also section, right after the Extended Summary.

----------
buf : StringIO-like, optional
buffer to write to
columns : sequence, optional
the subset of columns to write; default None writes all columns
Buffer to write to.
columns : sequence, optional, default None
The subset of columns to write. The default None writes all columns.
col_space : int, optional
the minimum width of each column
The minimum width of each column.
header : bool, optional
%(header)s
index : bool, optional
whether to print index (row) labels, default True
na_rep : string, optional
string representation of NAN to use, default 'NaN'
formatters : list or dict of one-parameter functions, optional
formatter functions to apply to columns' elements by position or name,
default None. The result of each function must be a unicode string.
%(header)s.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Substituting the header here won't break lines at 79 characters. Not sure this is worth fixing though.

index : bool, optional, default True
Whether to print index (row) labels.
na_rep : str, optional, default 'NaN'
String representation of NAN to use.
formatters : list or dict of one-param. functions, optional, default None
Formatter functions to apply to columns' elements by position or name.
The result of each function must be a unicode string.
List must be of length equal to the number of columns.
float_format : one-parameter function, optional
formatter function to apply to columns' elements if they are floats,
default None. The result of this function must be a unicode string.
sparsify : bool, optional
float_format : one-parameter function, optional, default None
Formatter function to apply to columns' elements if they are floats.
The result of this function must be a unicode string.
sparsify : bool, optional, default True
Set to False for a DataFrame with a hierarchical index to print every
multiindex key at each row, default True
index_names : bool, optional
Prints the names of the indexes, default True
line_width : int, optional
Width to wrap a line in characters, default no wrap
table_id : str, optional
id for the <table> element create by to_html

.. versionadded:: 0.23.0"""
multiindex key at each row.
index_names : bool, optional, default True
Prints the names of the indexes.
line_width : int, optional, default no wrap
Width to wrap a line in characters.
max_rows : int, optional
Maximum number of rows to display in the console.
max_cols : int, optional
Maximum number of columns to display in the console.
show_dimensions : bool, default False
Display dataframe's dimensions (number of rows by number of columns).
"""

_VALID_JUSTIFY_PARAMETERS = ("left", "right", "center", "justify",
"justify-all", "start", "end", "inherit",
Expand All @@ -103,14 +106,14 @@
* inherit
* match-parent
* initial
* unset
* unset.
"""

return_docstring = """

Returns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Returns section should go after the Parameters section and before the See Also section.

-------
formatted : string (or unicode, depending on data and options)"""
formatted : str (or unicode, depending on data and options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return explanation is missing. It should go in the next line, indented.

"""

docstring_to_string = common_docstring + justify_docstring + return_docstring

Expand Down