3

So I was previously running some code for a pollution dataset, and the code was running just fine. Now, I get this error: Colors must be aRGB hex values

The only line of code I have is the following:

pollution_jawn = pd.read_excel('ObservationData_irkfioc copy.xlsx')

I have no idea what the issue is, and I even tried deleting this file from my jupyterhub directory and uploading it, but even that did not work.

Krunal Desai
  • 39
  • 1
  • 2

4 Answers4

2

As mentioned by the other answer, a workaround this is to specify engine='xlrd' in pd.read_excel. However, for this to work, xlrd must be in version 1.2.0 (or lower).

To download the specific version (using anaconda), type in your terminal conda install -c anaconda xlrd=1.2.0.

After that is done, this should work (mind that you will get a FutureWarning, as this version of xlrd is deprecated:

pollution_jawn = pd.read_excel('ObservationData_irkfioc copy.xlsx', engine='xlrd')
1

Had a similar issue after I updated to pandas 1.2.3. What worked for me is to specify

pd.read_excel(path_to_xlsx, engine='xlrd')

I suspect that the xlsx file I loaded used an older xls standard somewhere, since the option "xlrd supports old-style Excel files (.xls)" (from the docs)

dieterw
  • 151
  • 1
  • 9
1

The .xlsx file was probably saved in an older version of Excel. What worked for me was to simply open the .xlsx file in a new version of Excel and then save it again. After that the error didn't turn up again.

bananaman
  • 39
  • 3
0

Had similar issue, but found simple solution, just to reassign method set in RGB class in openpyxl/styles/colors.py, catching error with 'Colors must be aRGB hex values' and setting another color like white:

from openpyxl.styles.colors import WHITE, RGB
__old_rgb_set__ = RGB.__set__

def __rgb_set_fixed__(self, instance, value):
    try:
        __old_rgb_set__(self, instance, value)
    except ValueError as e:
        if e.args[0] == 'Colors must be aRGB hex values':
            __old_rgb_set__(self, instance, WHITE)  # Change color here

 RGB.__set__ = __rgb_set_fixed__

Hope it will help somebody

Korney Burau
  • 26
  • 1
  • 4