1
Good afternoon,
I am trying to read an xlsx file in python via pandas, but it returns errors; as if the file did not exist (however it is in the same folder as the python script). I tried to pass the file path and it still didn’t work. Follow the code below. I am using jupyter lab, previously tried vscode but returned the same error...
import numpy as np
import pandas as pd
simulacao_projeto = pd.read_xlsx('simul.xlsx')
Following error that returns is:
AttributeError Traceback (most recent call last)
<ipython-input-6-1e337f1a57f3> in <module>
----> 1 simulacao_projeto = pd.read_xlsx('simul.xlsx')
AttributeError: module 'pandas' has no attribute 'read_xlsx'
Are you sure you are running the code you have placed? By the error message it appears you have executed
simulacao_projeto = pd._xlsx
.– Woss
I am running simulaca_project = pd.read_xlsx('')
– Felipe Roque
Ah, the error message was wrong. Have you checked the documentation to make sure that this method exists? Shouldn’t it be
read_excel
? At least in the version 0.25.2 documentation there is no methodread_xlsx
– Woss
I’ve tried to
read_excel
but returns an even bigger error. The file I want to read is Simul.xlsx, I already put it inside the same folder, I tried to pass the directory it is, but continues to return the same error...– Felipe Roque
The spreadsheet has nothing different, only four columns containing data from some sensors of a project I developed...
– Felipe Roque
I managed to solve the problem. Initially to read a file, you need to insert the directory where it is (as it was all in the same folder, I did not need to put). In the case of
simulacao_projeto = pd.read_xlsx('simul.xlsx')
we can notice in this line of code, that I had to insert ther
beforesimul.xlsx
(indicating that it was a directory) and changing thepd.read.xlsx
forpd.read_excel
staying nowsimul = pd.read_excel(r"simul.xlsx")
. With that, my code stopped displaying errors and ran as expected!– Felipe Roque
the
r
then it is unnecessary and does not indicate that it is a directory. It is a string prefix that exists in Python to inform that it is a raw string, or raw string, which will not escape the characters in the presence of the backslash. The problem was only to call the function, as we had already indicated.– Woss
The feature was called numerous times in various ways, watched several videos on youtube and researched in various locations and nothing worked. Yesterday I tried again for a video on youtube that just put this
r
before inserting the name of the file that the same longed to read and amazing that it seems worked. Follow the video of the comrade link.– Felipe Roque