From a36d4506d642843f66578bdf3a613670cb432d1b Mon Sep 17 00:00:00 2001 From: Gesa Stupperich Date: Sun, 20 Jun 2021 13:59:56 +0100 Subject: [PATCH] DOC: Substitute example in DataFrame.to_markdown docstring (#42126) --- pandas/core/frame.py | 3 +-- pandas/core/series.py | 45 ++++++++++++++++--------------------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 00f6213110e76..afbc857ac534b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2543,8 +2543,7 @@ def to_feather(self, path: FilePathOrBuffer[AnyStr], **kwargs) -> None: | 0 | elk | dog | +----+------------+------------+ | 1 | pig | quetzal | - +----+------------+------------+ - """, + +----+------------+------------+""", ) def to_markdown( self, diff --git a/pandas/core/series.py b/pandas/core/series.py index e94689383100d..53a8bb187d693 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1553,8 +1553,7 @@ def to_string( klass=_shared_doc_kwargs["klass"], storage_options=generic._shared_docs["storage_options"], examples=dedent( - """ - Examples + """Examples -------- >>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal") >>> print(s.to_markdown()) @@ -1564,7 +1563,21 @@ def to_string( | 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 | + +----+----------+""" ), ) def to_markdown( @@ -1607,31 +1620,7 @@ def to_markdown( ----- Requires the `tabulate `_ package. - 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 | - +----+----------+ + {examples} """ return self.to_frame().to_markdown( buf, mode, index, storage_options=storage_options, **kwargs