Skip to content

Commit 844b388

Browse files
DOC: Substitute example in DataFrame.to_markdown docstring (#42126) (#42144)
1 parent 87d7855 commit 844b388

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

pandas/core/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2540,8 +2540,7 @@ def to_feather(self, path: FilePathOrBuffer[AnyStr], **kwargs) -> None:
25402540
| 0 | elk | dog |
25412541
+----+------------+------------+
25422542
| 1 | pig | quetzal |
2543-
+----+------------+------------+
2544-
""",
2543+
+----+------------+------------+""",
25452544
)
25462545
def to_markdown(
25472546
self,

pandas/core/series.py

+17-28
Original file line numberDiff line numberDiff line change
@@ -1560,8 +1560,7 @@ def to_string(
15601560
klass=_shared_doc_kwargs["klass"],
15611561
storage_options=generic._shared_docs["storage_options"],
15621562
examples=dedent(
1563-
"""
1564-
Examples
1563+
"""Examples
15651564
--------
15661565
>>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal")
15671566
>>> print(s.to_markdown())
@@ -1571,7 +1570,21 @@ def to_string(
15711570
| 1 | pig |
15721571
| 2 | dog |
15731572
| 3 | quetzal |
1574-
"""
1573+
1574+
Output markdown with a tabulate option.
1575+
1576+
>>> print(s.to_markdown(tablefmt="grid"))
1577+
+----+----------+
1578+
| | animal |
1579+
+====+==========+
1580+
| 0 | elk |
1581+
+----+----------+
1582+
| 1 | pig |
1583+
+----+----------+
1584+
| 2 | dog |
1585+
+----+----------+
1586+
| 3 | quetzal |
1587+
+----+----------+"""
15751588
),
15761589
)
15771590
def to_markdown(
@@ -1614,31 +1627,7 @@ def to_markdown(
16141627
-----
16151628
Requires the `tabulate <https://pypi.org/project/tabulate>`_ package.
16161629
1617-
Examples
1618-
--------
1619-
>>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal")
1620-
>>> print(s.to_markdown())
1621-
| | animal |
1622-
|---:|:---------|
1623-
| 0 | elk |
1624-
| 1 | pig |
1625-
| 2 | dog |
1626-
| 3 | quetzal |
1627-
1628-
Output markdown with a tabulate option.
1629-
1630-
>>> print(s.to_markdown(tablefmt="grid"))
1631-
+----+----------+
1632-
| | animal |
1633-
+====+==========+
1634-
| 0 | elk |
1635-
+----+----------+
1636-
| 1 | pig |
1637-
+----+----------+
1638-
| 2 | dog |
1639-
+----+----------+
1640-
| 3 | quetzal |
1641-
+----+----------+
1630+
{examples}
16421631
"""
16431632
return self.to_frame().to_markdown(
16441633
buf, mode, index, storage_options=storage_options, **kwargs

0 commit comments

Comments
 (0)