I am new to machine learning and am creating a dataset using pandas in Python. I looked up a tutorial and was just trying out a basic code for creating a dataframe, but I keep getting the following trace-back:
AttributeError: 'module' object has no attribute 'read_csv'
I have saved the csv file in the csv(comma delimited) formatfrom Excel 13. Here's my code:
import pandas
import csv
mydata = pandas.read_csv('foo.csv')
target = mydata["Label"]
data = mydata.ix[:,:-1]
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.
Solution for AttributeError Errors and exceptions in Python can be handled using exception handling i.e. by using try and except in Python. Example: Consider the above class example, we want to do something else rather than printing the traceback Whenever an AttributeError is raised.
In this case, the Pandas read_csv() function returns a new DataFrame with the data and labels from the file data. csv , which you specified with the first argument. This string can be any valid path, including URLs.
A comma-separated values (csv) file is returned as two-dimensional data structure with labeled axes. See also DataFrame.to_csv. Write DataFrame to a comma-separated values (csv) file. read_csv.
There was a file named pandas.py
(and/or pandas.pyc
) in the working directory, which was imported instead of the pandas library. Removing or renaming the file/s solved the problem.
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