pandas.DataFrame.to_markdown¶
-
DataFrame.
to_markdown
(buf=None, mode=None, index=True, **kwargs)[source]¶ Print DataFrame in Markdown-friendly format.
New in version 1.0.0.
- Parameters
- bufstr, Path or StringIO-like, optional, default None
Buffer to write to. If None, the output is returned as a string.
- modestr, optional
Mode in which file is opened.
- indexbool, optional, default True
Add index (row) labels.
New in version 1.1.0.
- **kwargs
These parameters will be passed to tabulate.
- Returns
- str
DataFrame in Markdown-friendly format.
Examples
>>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal") >>> print(s.to_markdown()) | | animal | |---:|:---------| | 0 | elk | | 1 | pig | | 2 | dog | | 3 | quetzal |
Output markdown with a tabulate option.
>>> print(s.to_markdown(tablefmt="grid")) +----+----------+ | | animal | +====+==========+ | 0 | elk | +----+----------+ | 1 | pig | +----+----------+ | 2 | dog | +----+----------+ | 3 | quetzal | +----+----------+