Attributeerror: module ‘pandas’ has no attribute ‘read_csv’ ( Solved )

Attributeerror_ module 'pandas' has no attribute 'read_csv'

Pandas is a python package for dataframe creation and manipulating datasets. There are many inbuilt functions that allow performing a specific task very easily. The pandas.read_csv() is one of them. It allows you to read a CSV file and convert it to the dataframe. But sometimes you can get AttributeError: module ‘pandas’ has no attribute ‘read_csv’ error.  It creates a headache for many beginner coders to solve this issue. In this entire tutorial you will know how to solve this AttributError easily.

What is an AttributeError ?

The AttributeError comes when you are creating attributes of objects or variables. And the type of the variable does not support by the attribute method.

For example, if you apply the python append() method on a string variable then you will get the AttributError as the append() method does not support the string variable. Read the below article for more depth.

What is AttributeError in Python ? Complete Overview

The root cause for the  AttributeError : module ‘pandas’ has no attribute ‘read_csv’

The pandas read_csv() allows you to read a CSV file from a specific path. The root cause for this AttributError is that python is unable to interpret the read_csv() method.

Suppose I will read the following lines of code then I will get the AttributeError: module ‘pandas’ has no attribute ‘read_csv’.

import pandas as pd
data =pd.read_csv("sample_data.csv")
print(data)

Output

Traceback (most recent call last):
  File "C:/Users/Skrsu/Desktop/python/lessons/python.data/csv.py", line 1, in 
    import pandas as pd
  File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\__init__.py", line 37, in 
    import pandas.core.config_init
  File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\core\config_init.py", line 18, in 
    from pandas.formats.format import detect_console_encoding
  File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\formats\format.py", line 33, in 
    from pandas.io.common import _get_handle, UnicodeWriter, _expand_user
  File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\io\common.py", line 5, in 
    import csv
  File "C:\Users\Skrsu\Desktop\python\lessons\python.data\csv.py", line 4, in 
    df = pd.read_csv('sample_data.csv')
AttributeError: module 'pandas' has no attribute 'read_csv'

Solution for the AttributeError: module ‘pandas’ has no attribute ‘read_csv’

The solution for module ‘pandas’ has no attribute ‘read_csv’ error is very simple. You have to rename the csv.py file or remove the csv.py file. First, try to rename the csv.py file and then run the code. If the error persists then remove it completely.

Now again you will run the program, you will not get any errors.

import pandas as pd
df = pd.read_csv('sample_data.csv')
print(df)

Output

Removing the module 'pandas' has no attribute 'read_csv' error
Removing the module ‘pandas’ has no attribute ‘read_csv’ error

Conclusion

The AttributError comes when you are using a method that does support the type of the variable. The read_csv() is the python pandas method. The module ‘pandas’ has no attribute ‘read_csv’ comes as there is a file that needs to remove that is csv.py.

Read some more similar error resolutions.

dataframe’ object has no attribute ‘to_numpy’ ( Solved )

dataframe’ object has no attribute ‘dtype’ ( Solved )

I hope you have liked this tutorial. If you have any queries then you can contact us for more help.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner