From 064aec251be6122c41fe05377585d47e27e3306a Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Mon, 20 May 2019 01:55:42 -0400 Subject: [PATCH 1/4] DOC: #25723 passing kwargs to excel document engine --- doc/source/user_guide/io.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 0abd073c7dc07..97975c9621a48 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2864,6 +2864,16 @@ of sheet names can simply be passed to ``read_excel`` with no loss in performanc data = pd.read_excel('path_to_file.xls', ['Sheet1', 'Sheet2'], index_col=None, na_values=['NA']) +If control is needed over how a file is read, an ``xlrd`` workbook +created with the desired keyword arguments can be passed to ``ExcelFile``. + +.. code-block:: python + + xlrd_book = xlrd.open_workbook('path_to_file.xls', on_demand=True) + with pd.ExcelFile(xlrd_book) as xls: + df1 = pd.read_excel(xls, 'Sheet1') + df2 = pd.read_excel(xls, 'Sheet2') + .. _io.excel.specifying_sheets: Specifying Sheets From e910ca8e39b8e257c56b109d95186df670cfc1c0 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Mon, 20 May 2019 09:13:30 -0400 Subject: [PATCH 2/4] Reworded sentence for clarity --- doc/source/user_guide/io.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 97975c9621a48..c7952544c20cb 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2864,11 +2864,13 @@ of sheet names can simply be passed to ``read_excel`` with no loss in performanc data = pd.read_excel('path_to_file.xls', ['Sheet1', 'Sheet2'], index_col=None, na_values=['NA']) -If control is needed over how a file is read, an ``xlrd`` workbook -created with the desired keyword arguments can be passed to ``ExcelFile``. +``ExcelFile`` can also be called with a ``xlrd.book.Book`` object +as a parameter. This allows the user to control how the excel file is read. +For example, sheets can be loaded on demand by calling ``xlrd.open_workbook()`` +with ``on_demand=True``. .. code-block:: python - + xlrd_book = xlrd.open_workbook('path_to_file.xls', on_demand=True) with pd.ExcelFile(xlrd_book) as xls: df1 = pd.read_excel(xls, 'Sheet1') From 504ca06ff4c36acdd0fc02cc9d0072d21c6521fc Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Mon, 20 May 2019 09:17:42 -0400 Subject: [PATCH 3/4] added 'import xlrd' statement to fix flake8 error F821 --- doc/source/user_guide/io.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index c7952544c20cb..2caefdf5d4d8b 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2871,6 +2871,7 @@ with ``on_demand=True``. .. code-block:: python + import xlrd xlrd_book = xlrd.open_workbook('path_to_file.xls', on_demand=True) with pd.ExcelFile(xlrd_book) as xls: df1 = pd.read_excel(xls, 'Sheet1') From fd3f0c2c3854e77a13736716382f146d74967a41 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Mon, 20 May 2019 11:08:40 -0400 Subject: [PATCH 4/4] fixed linting errors on the code block --- doc/source/user_guide/io.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 2caefdf5d4d8b..88d8ccbbe036e 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2341,10 +2341,10 @@ round-trippable manner. .. ipython:: python df = pd.DataFrame({'foo': [1, 2, 3, 4], - 'bar': ['a', 'b', 'c', 'd'], - 'baz': pd.date_range('2018-01-01', freq='d', periods=4), - 'qux': pd.Categorical(['a', 'b', 'c', 'c']) - }, index=pd.Index(range(4), name='idx')) + 'bar': ['a', 'b', 'c', 'd'], + 'baz': pd.date_range('2018-01-01', freq='d', periods=4), + 'qux': pd.Categorical(['a', 'b', 'c', 'c']) + }, index=pd.Index(range(4), name='idx')) df df.dtypes @@ -2870,7 +2870,7 @@ For example, sheets can be loaded on demand by calling ``xlrd.open_workbook()`` with ``on_demand=True``. .. code-block:: python - + import xlrd xlrd_book = xlrd.open_workbook('path_to_file.xls', on_demand=True) with pd.ExcelFile(xlrd_book) as xls: