Skip to content

Commit a36d450

Browse files
DOC: Substitute example in DataFrame.to_markdown docstring (pandas-dev#42126)
1 parent 98e2229 commit a36d450

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,8 +2543,7 @@ def to_feather(self, path: FilePathOrBuffer[AnyStr], **kwargs) -> None:
25432543
| 0 | elk | dog |
25442544
+----+------------+------------+
25452545
| 1 | pig | quetzal |
2546-
+----+------------+------------+
2547-
""",
2546+
+----+------------+------------+""",
25482547
)
25492548
def to_markdown(
25502549
self,

pandas/core/series.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,8 +1553,7 @@ def to_string(
15531553
klass=_shared_doc_kwargs["klass"],
15541554
storage_options=generic._shared_docs["storage_options"],
15551555
examples=dedent(
1556-
"""
1557-
Examples
1556+
"""Examples
15581557
--------
15591558
>>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal")
15601559
>>> print(s.to_markdown())
@@ -1564,7 +1563,21 @@ def to_string(
15641563
| 1 | pig |
15651564
| 2 | dog |
15661565
| 3 | quetzal |
1567-
"""
1566+
1567+
Output markdown with a tabulate option.
1568+
1569+
>>> print(s.to_markdown(tablefmt="grid"))
1570+
+----+----------+
1571+
| | animal |
1572+
+====+==========+
1573+
| 0 | elk |
1574+
+----+----------+
1575+
| 1 | pig |
1576+
+----+----------+
1577+
| 2 | dog |
1578+
+----+----------+
1579+
| 3 | quetzal |
1580+
+----+----------+"""
15681581
),
15691582
)
15701583
def to_markdown(
@@ -1607,31 +1620,7 @@ def to_markdown(
16071620
-----
16081621
Requires the `tabulate <https://pypi.org/project/tabulate>`_ package.
16091622
1610-
Examples
1611-
--------
1612-
>>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal")
1613-
>>> print(s.to_markdown())
1614-
| | animal |
1615-
|---:|:---------|
1616-
| 0 | elk |
1617-
| 1 | pig |
1618-
| 2 | dog |
1619-
| 3 | quetzal |
1620-
1621-
Output markdown with a tabulate option.
1622-
1623-
>>> print(s.to_markdown(tablefmt="grid"))
1624-
+----+----------+
1625-
| | animal |
1626-
+====+==========+
1627-
| 0 | elk |
1628-
+----+----------+
1629-
| 1 | pig |
1630-
+----+----------+
1631-
| 2 | dog |
1632-
+----+----------+
1633-
| 3 | quetzal |
1634-
+----+----------+
1623+
{examples}
16351624
"""
16361625
return self.to_frame().to_markdown(
16371626
buf, mode, index, storage_options=storage_options, **kwargs

0 commit comments

Comments
 (0)