pandas.DataFrame.to_string

pandas 3.1.1 · DataFrame · method

Return a human-readable textual representation or write it to the supplied buffer.

Call syntax

DataFrame.to_string(…) Full signature
DataFrame.to_string(
    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,
    max_rows=None,
    max_cols=None,
    show_dimensions=False,
    decimal='.',
    line_width=None,
    min_rows=None,
    max_colwidth=None,
    encoding=None,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
buf Optional
Positional or keyword
Default None
str, Path or StringIO-like

Supply a destination file-like buffer, or use the default to return or print the output as documented.

columns Optional
Keyword only
Default None
array-like

Supply column labels or control how columns are handled.

col_space Optional
Keyword only
Default None
int, list or dict of int
header Optional
Keyword only
Default True
bool or list of str

Define which row or rows provide column names, or control whether to write them.

index Optional
Keyword only
Default True
bool

Supply row labels or control how existing row labels are used.

na_rep Optional
Keyword only
Default 'NaN'
str

Choose the text used to display missing values.

formatters Optional
Keyword only
Default None
list, tuple or dict of one-param. functions

Pass per-column or per-value formatting functions.

float_format Optional
Keyword only
Default None
one-parameter function

Provide a format string or callable to control numeric display.

sparsify Optional
Keyword only
Default None
bool
index_names Optional
Keyword only
Default True
bool
justify Optional
Keyword only
Default None
str
max_rows Optional
Keyword only
Default None
int
max_cols Optional
Keyword only
Default None
int

Limit the columns included in the displayed summary.

show_dimensions Optional
Keyword only
Default False
bool
decimal Optional
Keyword only
Default '.'
str

Identify the character used as the decimal mark.

line_width Optional
Keyword only
Default None
int
min_rows Optional
Keyword only
Default None
int
max_colwidth Optional
Keyword only
Default None
int
encoding Optional
Keyword only
Default None
str

Name a text encoding such as "utf-8".

Returns

str or None