47

I have the -current- latest version of pandas, openpyxl, xlrd.

openpyxl : 3.0.6.
pandas : 1.2.2.
xlrd : 2.0.1.

I have a generated excel xlsx- file (export from a webapplication).
I read it in pandas:

myexcelfile = pd.read_excel(easy_payfile, engine="openpyxl")

Everything goes ok, I can successfully read the file.

But I do get a warning:

/Users/*******/projects/environments/venv/lib/python3.8/site-packages/openpyxl/styles/stylesheet.py:214: UserWarning: Workbook contains no default style, apply openpyxl's default
  warn("Workbook contains no default style, apply openpyxl's default")

The documentation doesn't shed too much light on it.

Is there any way I can add an option to avoid this warning?

I prefer not to suppress it.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Philippe
  • 707
  • 1
  • 5
  • 9
  • 1
    It's a warning telling you that openpyxl might have to make some choices. – Charlie Clark Feb 16 '21 at 10:04
  • 4
    Hello, thanks for responding. That I can understand. Is there a way I can tell openpyxl what choice it has to make so it doesn't show this warning ? – Philippe Feb 18 '21 at 10:36
  • No and the warning is self-explanatory: the workbook contains no stylesheet so openpyxl will use its default. – Charlie Clark Feb 18 '21 at 11:02
  • 15
    And this is a 'warning' because? – Philippe Feb 20 '21 at 09:53
  • 2
    Because it's informational: the file might look different than you expect after processing. For example, number formats in the styles determine whether numbers are treated as dates or times. – Charlie Clark Oct 21 '21 at 07:54

7 Answers7

25

I don't think the library offers you a way to disable this thus you are going to need to use the warnings package directly.

A simple and punctual solution to the problem would be doing:

import warnings

with warnings.catch_warnings(record=True):
    warnings.simplefilter("always")
    myexcelfile = pd.read_excel(easy_payfile, engine="openpyxl")
ruhanbidart
  • 4,564
  • 1
  • 26
  • 13
  • Am I right in understanding that because of the "with", outside this clause we are not turning off the warnings? – YGA Feb 12 '23 at 18:23
8

@ruhanbidart solution is better than mine because you turn off warnings just for the call to read_excel, but if you have dozens of calls to pd.read_excel, you can simply disable all warnings:

import warnings
warnings.simplefilter("ignore")
neves
  • 33,186
  • 27
  • 159
  • 192
4

df=pd.read_excel("my.xlsx",engine="openpyxl") passing the engine parameter got rid of the warning for me. Default = None, so I think it is just warning you that it using openpyxl for default style.

Jose Urena
  • 59
  • 1
  • 3
  • 5
    Specifying engine really doesn't make the warning noise any lower. Catching warnings does help as @ruhanbidart suggests. – Jari Turkia Jun 22 '22 at 12:54
3

I had the same warning. Just changed the sheet name of my excel file from "sheet_1" to "Sheet1", then the warning disappeared. very similar with Yoan. I think pandas should fix this warning later.

taichi_tiger
  • 809
  • 1
  • 7
  • 18
2

I had the exact same warning and was unable to read the file. In my case the problem was coming from the Sheet name in the Excel file.

The initial name contained a . (ex: MDM.TARGET) I simply replace the . with _ and everything's fine.

Yoan B. M.Sc
  • 1,485
  • 5
  • 18
1

In my situation some columns' names had a dollar sign ($) in them. Replacing '$' to '_' solved the issue.

Julie V
  • 11
  • 1
1

In my case it was the sheet name. From Sheet0 I renamed it to Sheet1

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 27 '23 at 22:04