Skip to content

Commit fc3b368

Browse files
DOC: Showcase usage of argument notes in pandas.read_excel() (pandas-dev#58070)
Co-authored-by: diogomsmiranda <[email protected]>
1 parent d8a6705 commit fc3b368

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

pandas/io/excel/_base.py

+35
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@
280280
281281
engine_kwargs : dict, optional
282282
Arbitrary keyword arguments passed to excel engine.
283+
284+
notes: DataFrame, default None
285+
A DataFrame to hold the notes extracted from the Excel file.
283286
284287
Returns
285288
-------
@@ -353,6 +356,38 @@
353356
0 string1 1.0
354357
1 string2 2.0
355358
2 None NaN
359+
360+
To get the comments of the excel input file, pass a ``notes`` DataFrame.
361+
This new DataFrame might have different dimensions than the data returned
362+
DataFrame since it'll only read the columns which cells have notes.
363+
(last column with note - first column with note + 1) *
364+
(last row with note - first row with note + 1).
365+
366+
Cells with no notes will have an empty string ("").
367+
368+
If the data in the ``tmp.xlsx`` file was written using the
369+
``set_tooltips(notes)`` method of ``Styler.to_excel``, like in
370+
the example below:
371+
372+
>>> notes = pd.DataFrame(
373+
... [["note 1", "note 2"], ["", "note 4"], ["note 5", ""]],
374+
... ) # doctest: +SKIP
375+
376+
>>> df.style.set_tooltips(notes).to_excel('tmp.xlsx') # doctest: +SKIP
377+
378+
>>> df_notes = pd.DataFrame() # doctest: +SKIP
379+
380+
>>> pd.read_excel('tmp.xlsx', df_notes) # doctest: +SKIP
381+
Name Value
382+
0 string1 1
383+
1 string2 2
384+
2 #Comment 3
385+
386+
>>> df_notes # doctest: +SKIP
387+
0 1
388+
0 note 1 note 2
389+
1 note 4
390+
2 note 5
356391
"""
357392
)
358393

pandas/io/formats/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def set_tooltips(
566566
567567
>>> notes = pd.DataFrame(
568568
... [["cell 1", "cell 2"], ["cell 3", "cell 4"]],
569-
... )
569+
... ) # doctest: +SKIP
570570
>>> df1.style.set_tooltips(notes).to_excel("output.xlsx") # doctest: +SKIP
571571
"""
572572
),

0 commit comments

Comments
 (0)