cudf.DataFrame.to_string#

DataFrame.to_string(
buf=None,
*,
columns=None,
col_space=None,
header=True,
index: bool = True,
na_rep: str = 'NaN',
formatters=None,
float_format=None,
sparsify: bool | None = None,
index_names: bool = True,
justify: str | None = None,
max_rows: int | None = None,
max_cols: int | None = None,
show_dimensions: bool = False,
decimal: str = '.',
line_width: int | None = None,
min_rows: int | None = None,
max_colwidth: int | None = None,
encoding: str | None = None,
) str | None[source]#

Render a DataFrame to a console-friendly tabular output.

cuDF uses pandas internals for string formatting, so this mirrors pandas.DataFrame.to_string() and accepts the same arguments. Unlike repr, the output is not truncated by the display.max_rows/display.max_columns options unless max_rows/max_cols are passed explicitly.

cuDF supports null/None as a value in any column type, which is transparently supported during this output process.

Parameters:
bufwritable buffer, optional

File path or buffer to write to. If None (default), the output is returned as a string.

columnssequence, optional

The subset of columns to write. Writes all columns by default.

col_spaceint, list or dict of int, optional

The minimum width of each column.

headerbool or list of str, default True

Whether to write the column names. If a list of strings is given, it is assumed to be aliases for the column names.

indexbool, default True

Whether to print index (row) labels.

na_repstr, default “NaN”

String representation of NaN/null values.

formatterslist, tuple or dict of callables, optional

One-parameter formatter functions to apply to columns’ elements by position or name.

float_formatcallable, optional

One-parameter formatter function applied to floating point values.

sparsifybool, optional

Set to False for a DataFrame with a hierarchical index to print every multiindex key at each row. Defaults to True.

index_namesbool, default True

Whether to print the names of the indexes.

justifystr, optional

How to justify the column labels (e.g. "left", "right", "center"). Defaults to the pandas display option.

max_rowsint, optional

Maximum number of rows to display before truncating.

max_colsint, optional

Maximum number of columns to display before truncating.

show_dimensionsbool, default False

Whether to display the DataFrame dimensions (number of rows and columns).

decimalstr, default “.”

Character recognized as the decimal separator, e.g. "," in Europe.

line_widthint, optional

Width, in characters, at which to wrap a line.

min_rowsint, optional

Number of rows to show in a truncated output (when the number of rows exceeds max_rows).

max_colwidthint, optional

Maximum width, in characters, to truncate each column. By default there is no limit.

encodingstr, optional

Character encoding to use when writing to buf.

Returns:
str or None

The string representation of the DataFrame when buf is None; otherwise the result is written to buf and None is returned.

Examples

>>> import cudf
>>> df = cudf.DataFrame()
>>> df['key'] = [0, 1, 2]
>>> df['val'] = [float(i + 10) for i in range(3)]
>>> df.to_string()
'   key   val\n0    0  10.0\n1    1  11.0\n2    2  12.0'