Skip to content

Commit bd039d4

Browse files
DOC: Showcase writing comments in Styler.to_excel() (pandas-dev#58070)
Co-authored-by: diogomsmiranda <[email protected]>
1 parent c5c4854 commit bd039d4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pandas/core/generic.py

+2
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,7 @@ def _repr_data_resource_(self):
21252125
Arbitrary keyword arguments passed to excel engine.
21262126
"""
21272127
),
2128+
extra_examples="",
21282129
)
21292130
def to_excel(
21302131
self,
@@ -2256,6 +2257,7 @@ def to_excel(
22562257
automatically chosen depending on the file extension):
22572258
22582259
>>> df1.to_excel("output1.xlsx", engine="xlsxwriter") # doctest: +SKIP
2260+
{extra_examples}
22592261
"""
22602262
if engine_kwargs is None:
22612263
engine_kwargs = {}

pandas/io/formats/style.py

+15
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
except ImportError:
9393
has_mpl = False
9494

95+
import textwrap
96+
9597

9698
@contextmanager
9799
def _mpl(func: Callable) -> Generator[tuple[Any, Any], None, None]:
@@ -555,6 +557,19 @@ def set_tooltips(
555557
storage_options=_shared_docs["storage_options"],
556558
storage_options_versionadded="1.5.0",
557559
extra_parameters="",
560+
extra_examples=textwrap.dedent(
561+
"""\
562+
If you wish to write excel notes to the workbook, you can do so by
563+
passing a DataFrame to ``set_tooltips``. This process is independent
564+
from writing data to the workbook, therefore both DataFrames can have
565+
different dimensions.
566+
567+
>>> notes = pd.DataFrame(
568+
... [["cell 1", "cell 2"], ["cell 3", "cell 4"]],
569+
... )
570+
>>> df1.style.set_tooltips(notes).to_excel("output.xlsx") # doctest: +SKIP
571+
"""
572+
),
558573
)
559574
def to_excel(
560575
self,

0 commit comments

Comments
 (0)