diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 1fb54ae55b90e..007f5b7feb060 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -24,7 +24,8 @@ New features the user to override the engine's default behavior to include or omit the dataframe's indexes from the resulting Parquet file. (:issue:`20768`) - :meth:`DataFrame.corr` and :meth:`Series.corr` now accept a callable for generic calculation methods of correlation, e.g. histogram intersection (:issue:`22684`) - +- :func:`DataFrame.to_string` now accepts ``decimal`` as an argument, allowing +the user to specify which decimal separator should be used in the output. (:issue:`23614`) .. _whatsnew_0240.enhancements.extension_array_operators: @@ -1002,6 +1003,7 @@ Other API Changes - :class:`DateOffset` attribute `_cacheable` and method `_should_cache` have been removed (:issue:`23118`) - Comparing :class:`Timedelta` to be less or greater than unknown types now raises a ``TypeError`` instead of returning ``False`` (:issue:`20829`) - :meth:`Index.hasnans` and :meth:`Series.hasnans` now always return a python boolean. Previously, a python or a numpy boolean could be returned, depending on circumstances (:issue:`23294`). +- The order of the arguments of :func:`DataFrame.to_html` and :func:`DataFrame.to_string` is rearranged to be consistent with each other. (:issue:`23614`) .. _whatsnew_0240.deprecations: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 30ca7d82936c0..e313e0f37a445 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2035,24 +2035,21 @@ def to_parquet(self, fname, engine='auto', compression='snappy', 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, - line_width=None, max_rows=None, max_cols=None, - show_dimensions=False): + max_rows=None, max_cols=None, show_dimensions=False, + decimal='.', line_width=None): """ Render a DataFrame to a console-friendly tabular output. - %(shared_params)s line_width : int, optional Width to wrap a line in characters. - %(returns)s - See Also -------- to_html : Convert DataFrame to HTML. Examples -------- - >>> d = {'col1' : [1, 2, 3], 'col2' : [4, 5, 6]} + >>> d = {'col1': [1, 2, 3], 'col2': [4, 5, 6]} >>> df = pd.DataFrame(d) >>> print(df.to_string()) col1 col2 @@ -2068,42 +2065,37 @@ def to_string(self, buf=None, columns=None, col_space=None, header=True, sparsify=sparsify, justify=justify, index_names=index_names, header=header, index=index, - line_width=line_width, max_rows=max_rows, max_cols=max_cols, - show_dimensions=show_dimensions) + show_dimensions=show_dimensions, + decimal=decimal, + line_width=line_width) formatter.to_string() if buf is None: result = formatter.buf.getvalue() return result - @Substitution(header='whether to print column labels, default True') + @Substitution(header='Whether to print column labels, default True') @Substitution(shared_params=fmt.common_docstring, returns=fmt.return_docstring) def to_html(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, bold_rows=True, - classes=None, escape=True, max_rows=None, max_cols=None, - show_dimensions=False, notebook=False, decimal='.', - border=None, table_id=None): + sparsify=None, index_names=True, justify=None, max_rows=None, + max_cols=None, show_dimensions=False, decimal='.', + bold_rows=True, classes=None, escape=True, + notebook=False, border=None, table_id=None): """ Render a DataFrame as an HTML table. - %(shared_params)s - bold_rows : boolean, default True - Make the row labels bold in the output + bold_rows : bool, default True + Make the row labels bold in the output. classes : str or list or tuple, default None - CSS class(es) to apply to the resulting html table - escape : boolean, default True + CSS class(es) to apply to the resulting html table. + escape : bool, default True Convert the characters <, >, and & to HTML-safe sequences. notebook : {True, False}, default False Whether the generated HTML is for IPython Notebook. - decimal : string, default '.' - Character recognized as decimal separator, e.g. ',' in Europe - - .. versionadded:: 0.18.0 - border : int A ``border=border`` attribute is included in the opening `