pandas / 1.4.0 / reference / api / pandas.dataframe.to_markdown.html /

pandas.DataFrame.to_markdown

DataFrame. to_markdown ( buf=None, mode='wt', index=True, storage_options=None, **kwargs ) [source]

Print DataFrame in Markdown-friendly format.

New in version 1.0.0.

Parameters
buf :str, Path or StringIO-like, optional, default None

Buffer to write to. If None, the output is returned as a string.

mode :str, optional

Mode in which file is opened, “wt” by default.

index :bool, optional, default True

Add index (row) labels.

New in version 1.1.0.

storage_options :dict, optional

Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.

New in version 1.2.0.

**kwargs

These parameters will be passed to tabulate.

Returns
str

DataFrame in Markdown-friendly format.

Notes

Requires the tabulate package.

Examples

>>> df = pd.DataFrame(
...     data={"animal_1": ["elk", "pig"], "animal_2": ["dog", "quetzal"]}
... )
>>> print(df.to_markdown())
|    | animal_1   | animal_2   |
|---:|:-----------|:-----------|
|  0 | elk        | dog        |
|  1 | pig        | quetzal    |

Output markdown with a tabulate option.

>>> print(df.to_markdown(tablefmt="grid"))
+----+------------+------------+
|    | animal_1   | animal_2   |
+====+============+============+
|  0 | elk        | dog        |
+----+------------+------------+
|  1 | pig        | quetzal    |
+----+------------+------------+

© 2008–2022, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/1.4.0/reference/api/pandas.DataFrame.to_markdown.html