I have been successfully using pandas.read_csv
since long but suddenly it starts giving the error while I try to read a csv file
df = pd.read_csv('file.csv', encoding='utf-8')
The error is
AttributeError: module 'pandas' has no attribute 'read_csv'
I have tried to upgrade pandas but does not work. I tried to search and got this answer but when I search csv.py file in my pandas I didn't find any. So i tried to hover over the pandas.read_csv
method which takes me to parsers.py
file. But in that file there is no specific method named read_csv
but it directed to another parser funtion like this
# parser.py (built-in file in pandas) file has this implementation
read_csv = _make_parser_function('read_csv', sep=',')
read_csv = Appender(_read_csv_doc)(read_csv)
I don't understand how should it start working again ? Any suggestions
The Python "AttributeError module 'pandas' has no attribute 'read_csv'" occurs when we have a local file named pandas.py or csv.py and try to import from the pandas module. To solve the error, make sure to rename any local files named pandas.py .
The Python "AttributeError module 'pandas' has no attribute 'Series'" occurs when we have a local file named pandas.py or misspell Series (case-sensitive). To solve the error, make sure to rename any local files named pandas.py . Here is an example of how the error occurs in a file called pandas.py .
Pandas is usually imported under the pd alias. alias: In Python alias are an alternate name for referring to the same thing. Create an alias with the as keyword while importing: import pandas as pd. Now the Pandas package can be referred to as pd instead of pandas .
I had the same problem when trying to run the following code in Jupyter/ipython.
import pandas as pd
df = pd.read_csv("weather_data.csv")
df
I realized I had a file named pandas.py. In fact, had two others named pandas1.py and pandas2.py as well. I changed them all and then it worked perfectly:) Lesson learned.
So I am writing an answer myself. I just noticed that I created a file random.py
in my project which was creating a conflict with random.py
in pandas
package. Renaming my current file to something else worked for me :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With