Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16684

Pandas can't open an XLSX file

$
0
0

I'm trying to open a XLSX file and and I encounter unforeseen difficulties.

Here is my code:

df=pd.read_excel('data - 2017.xlsx')print(df.head())

Here is the first error message:

Traceback (most recent call last):  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/base.py", line 55, in _convert    value = expected_type(value)TypeError: Fill() takes no argumentsDuring handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/Users/X/PycharmProjects/compta/extraction.py", line 7, in <module>    df=pd.read_excel('data -2017.xlsx')  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/util/_decorators.py", line 311, in wrapper    return func(*args, **kwargs)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 364, in read_excel    io = ExcelFile(io, storage_options=storage_options, engine=engine)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 1233, in __init__    self._reader = self._engines[engine](self._io, storage_options=storage_options)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_openpyxl.py", line 522, in __init__    super().__init__(filepath_or_buffer, storage_options=storage_options)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 420, in __init__    self.book = self.load_workbook(self.handles.handle)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_openpyxl.py", line 533, in load_workbook    return load_workbook(  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 317, in load_workbook    reader.read()  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 281, in read    apply_stylesheet(self.archive, self.wb)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/styles/stylesheet.py", line 198, in apply_stylesheet    stylesheet = Stylesheet.from_tree(node)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/styles/stylesheet.py", line 103, in from_tree    return super(Stylesheet, cls).from_tree(node)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/serialisable.py", line 103, in from_tree    return cls(**attrib)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/styles/stylesheet.py", line 74, in __init__    self.fills = fills  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/sequence.py", line 26, in __set__    seq = [_convert(self.expected_type, value) for value in seq]  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/sequence.py", line 26, in <listcomp>    seq = [_convert(self.expected_type, value) for value in seq]  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/base.py", line 57, in _convert    raise TypeError('expected '+ str(expected_type))TypeError: expected <class 'openpyxl.styles.fills.Fill'>Process finished with exit code 1

I read other posts on Stack Overflow. Among other adivce, I tried to add

engine="openpyxl"

Still the same issue. I also tried pd.ExcelFile, the result is below.

Here is my code:

import pandas as pddf = pd.ExcelFile('data - 2017.xlsx', engine='openpyxl')print(df)

After running that, it gives me the the following error:

Traceback (most recent call last):  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/base.py", line 55, in _convert    value = expected_type(value)TypeError: Fill() takes no argumentsDuring handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/Users/X/PycharmProjects/compta/extraction.py", line 3, in <module>    df = pd.ExcelFile('data - 2017.xlsx', engine='openpyxl')  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 1233, in __init__    self._reader = self._engines[engine](self._io, storage_options=storage_options)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_openpyxl.py", line 522, in __init__    super().__init__(filepath_or_buffer, storage_options=storage_options)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 420, in __init__    self.book = self.load_workbook(self.handles.handle)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_openpyxl.py", line 533, in load_workbook    return load_workbook(  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 317, in load_workbook    reader.read()  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 281, in read    apply_stylesheet(self.archive, self.wb)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/styles/stylesheet.py", line 198, in apply_stylesheet    stylesheet = Stylesheet.from_tree(node)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/styles/stylesheet.py", line 103, in from_tree    return super(Stylesheet, cls).from_tree(node)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/serialisable.py", line 103, in from_tree    return cls(**attrib)  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/styles/stylesheet.py", line 74, in __init__    self.fills = fills  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/sequence.py", line 26, in __set__    seq = [_convert(self.expected_type, value) for value in seq]  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/sequence.py", line 26, in <listcomp>    seq = [_convert(self.expected_type, value) for value in seq]  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openpyxl/descriptors/base.py", line 57, in _convert    raise TypeError('expected '+ str(expected_type))TypeError: expected <class 'openpyxl.styles.fills.Fill'>Process finished with exit code 1

I, of course, updatd Python and Openpyxl.


Viewing all articles
Browse latest Browse all 16684

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>