Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'pandas' has no attribute 'read_csv' Python3.5

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

like image 262
muazfaiz Avatar asked Apr 29 '17 13:04

muazfaiz


People also ask

How to fix AttributeError module pandas has no attribute read_ csv?

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 .

How do I fix pandas has no attribute Series?

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 .

What is PD in Python?

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 .


2 Answers

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.

like image 92
Drew Avatar answered Oct 16 '22 18:10

Drew


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 :)

like image 31
muazfaiz Avatar answered Oct 16 '22 18:10

muazfaiz