0

Since read_exceldefault engine xlrd has been deprecated in newer pandas releases, how do I make openpyxl the default engine of all my pd.read_excel calls?

Now, if I update pandas, I must put the parameter engine="openpyxl" in all my pd.read_excel calls. It looks unnecessary.

neves
  • 33,186
  • 27
  • 159
  • 192
  • 1
    From the [docs](https://pandas.pydata.org/pandas-docs/version/1.2.0/reference/api/pandas.read_excel.html#pandas.read_excel): Otherwise if path_or_buffer is an xls format, xlrd will be used., **Otherwise if openpyxl is installed, then openpyxl will be used**. – BigBen Mar 22 '21 at 14:23

2 Answers2

1

It's easy! You can do it by changing the default values of the method by going to the _base.py inside the environment's pandas folder. You can find it as follows:

import pandas as pd
print(pd.__file__)

Once in the pandas folder, dive into the folder io > excel > _base.py

Open the file and find

def read_excel(...)

You will find the default value for engine. Change it to 'openpyxl'

If you're using vscode, simply right click on the instance of the method .read_excel and press F12, or go to the definition and change it right away.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Uriel_GC
  • 11
  • 1
0

If you're using pandas version 1.1.5 or other new version this might help:

Run print(pd.__file__) to see where your pandas library is stored. Usually, the file path would end in "Lib\site-packages\pandas". Then, open folder "io" and folder "excel" right after. You will find there the "_base.py" file.

Look for the def __init__. You will find there the default engine to read Excel files. It should be on line 849. I should read:

if engine is None:
    engine = "openpyxl"