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 attributerror 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 attributeerror as the append() method does not support the string variable. Read the below article for more depth.
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)
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)
The attribute error 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.
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.