Python - Data Analysis - Error reading file in xlsx format

Asked

Viewed 79 times

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.

  • I am running simulaca_project = pd.read_xlsx('')

  • 2

    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 method read_xlsx

  • 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...

  • The spreadsheet has nothing different, only four columns containing data from some sensors of a project I developed...

  • 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 the r before simul.xlsx (indicating that it was a directory) and changing the pd.read.xlsx for pd.read_excel staying now simul = pd.read_excel(r"simul.xlsx"). With that, my code stopped displaying errors and ran as expected!

  • 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.

  • 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.

Show 3 more comments

1 answer

0

The function to be used is "read_excel", because "read_xlsx" does not exist in pandas:

  • I understand, I know that it does not 'exist'. But there was only the need to insert the r on the path I mentioned above. Hugs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.