Pandas DataFrame: to_string() function
DataFrame - to_string() function
The to_string() function is used to render a DataFrame to a console-friendly tabular output.
Syntax:
DataFrame.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, max_rows=None, min_rows=None, max_cols=None, show_dimensions=False, decimal='.', line_width=None)
Parameters:
Name | Description | Type / Default Value | Required / Optional |
---|---|---|---|
buf | Buffer to write to. | StringIO-like | Optional |
columns | The subset of columns to write. Writes all columns by default. | sequence Default Value: None |
Optional |
col_space | The minimum width of each column. | int | Optional |
header | Write out the column names. If a list of strings is given, it is assumed to be aliases for the column names. | bool | Optional |
index | Whether to print index (row) labels. | bool Default Value: True |
Optional |
na_rep | String representation of NAN to use. | str Default Value: ‘NaN’ |
Optional |
formatters | 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. | ist or dict of one-param. functions | Optional |
float_format | Formatter function to apply to columns’ elements if they are floats. The result of this function must be a unicode string. | one-parameter function Default Value: None |
Optional |
sparsify | Set to False for a DataFrame with a hierarchical index to print every multiindex key at each row. | bool Default Value: True |
Optional |
index_names | Prints the names of the indexes. | bool Default Value: True |
Optional |
justify | 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
|
str Default Value: None |
Required |
max_rows | Maximum number of rows to display in the console. | int | Optional |
min_rows | The number of rows to display in the console in a truncated repr (when number of rows is above max_rows). | int | Optional |
max_cols | Maximum number of columns to display in the console. | int | Optional |
show_dimensions | Display DataFrame dimensions (number of rows by number of columns). | bool Default Value: False |
Required |
decimal | Character recognized as decimal separator, e.g. ',' in Europe. | str Default Value: '.' |
Required |
line_width | Width to wrap a line in characters. | int | Optional |
Returns:
str (or unicode, depending on data and options)
String representation of the dataframe.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - to_records() function
Next: DataFrame - to_clipboard() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/pandas/dataframe/dataframe-to_string.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics