pandas.DataFrame.to_markdown

DataFrame.to_markdown(self, buf: Union[IO[str], NoneType] = None, mode: Union[str, NoneType] = None, **kwargs) → Union[str, NoneType][source]

Print DataFrame in Markdown-friendly format.

New in version 1.0.0.

Parameters
bufwritable buffer, defaults to sys.stdout

Where to send the output. By default, the output is printed to sys.stdout. Pass a writable buffer if you need to further process the output.

modestr, optional

Mode in which file is opened.

**kwargs

These parameters will be passed to tabulate.

Returns
str

DataFrame in Markdown-friendly format.

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    |