Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Classe « DataFrame »

Méthode pandas.DataFrame.to_string

Signature de la méthode to_string

def to_string(self, buf: 'Optional[FilePathOrBuffer[str]]' = None, columns: 'Optional[Sequence[str]]' = None, col_space: 'Optional[int]' = None, header: 'Union[bool, Sequence[str]]' = True, index: 'bool' = True, na_rep: 'str' = 'NaN', formatters: 'Optional[fmt.FormattersType]' = None, float_format: 'Optional[fmt.FloatFormatType]' = None, sparsify: 'Optional[bool]' = None, index_names: 'bool' = True, justify: 'Optional[str]' = None, max_rows: 'Optional[int]' = None, min_rows: 'Optional[int]' = None, max_cols: 'Optional[int]' = None, show_dimensions: 'bool' = False, decimal: 'str' = '.', line_width: 'Optional[int]' = None, max_colwidth: 'Optional[int]' = None, encoding: 'Optional[str]' = None) -> 'Optional[str]' 

Description

to_string.__doc__

        Render a DataFrame to a console-friendly tabular output.
        
        Parameters
        ----------
        buf : str, Path or StringIO-like, optional, default None
            Buffer to write to. If None, the output is returned as a string.
        columns : sequence, optional, default None
            The subset of columns to write. Writes all columns by default.
        col_space : int, list or dict of int, optional
            The minimum width of each column.
        header : bool or sequence, optional
            Write out the column names. If a list of strings is given, it is assumed to be aliases for the column names.
        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, tuple or dict of one-param. functions, optional
            Formatter functions to apply to columns' elements by position or
            name.
            The result of each function must be a unicode string.
            List/tuple must be of length equal to the number of columns.
        float_format : one-parameter function, optional, default None
            Formatter function to apply to columns' elements if they are
            floats. This function must return a unicode string and will be
            applied only to the non-``NaN`` elements, with ``NaN`` being
            handled by ``na_rep``.

            .. versionchanged:: 1.2.0

        sparsify : bool, optional, default True
            Set to False for a DataFrame with a hierarchical index to print
            every multiindex key at each row.
        index_names : bool, optional, default True
            Prints the names of the indexes.
        justify : str, default None
            How to justify the column labels. If None uses the option from
            the print configuration (controlled by set_option), 'right' out
            of the box. Valid values are

            * left
            * right
            * center
            * justify
            * justify-all
            * start
            * end
            * inherit
            * match-parent
            * initial
            * unset.
        max_rows : int, optional
            Maximum number of rows to display in the console.
        min_rows : int, optional
            The number of rows to display in the console in a truncated repr
            (when number of rows is above `max_rows`).
        max_cols : int, optional
            Maximum number of columns to display in the console.
        show_dimensions : bool, default False
            Display DataFrame dimensions (number of rows by number of columns).
        decimal : str, default '.'
            Character recognized as decimal separator, e.g. ',' in Europe.
    
        line_width : int, optional
            Width to wrap a line in characters.
        max_colwidth : int, optional
            Max width to truncate each column in characters. By default, no limit.

            .. versionadded:: 1.0.0
        encoding : str, default "utf-8"
            Set character encoding.

            .. versionadded:: 1.0
        
        Returns
        -------
        str or None
            If buf is None, returns the result as a string. Otherwise returns
            None.
    
        See Also
        --------
        to_html : Convert DataFrame to HTML.

        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