简体   繁体   中英

no attribute named read_csv in pandas python

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]

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.

More likely you have not installed pandas correctly . For me installing pandas correctly got me through this error . Here goes the installation .....

sudo apt-get install python-numpy cython

This will install a fast numeric processing library (numpy) and a tool required in the pandas build process (cython).

Test numpy

Open up a Python prompt by running the following:

python

At the prompt, type the following:

 >>> import numpy
 >>> print numpy.__version__

You should see a number like "1.6.1" or higher.

Test cython

Open up a Python prompt by running the following:

python

At the prompt, type the following (capitalization matters!):

 >>> import Cython
 >>> print Cython.__version__

You should see a number like "0.15.1" or higher.

Download pandas

We recommend storing pandas in a directory called ''projects'' in your user directory. To do that, run the following commands:

mkdir -p ~/projects
cd ~/projects
git clone https://github.com/pydata/pandas.git
cd pandas

You will see git download pandas. Once the download finishes, and you get your prompt back, proceed to the next step.

Build pandas

To build pandas, you have to run the following two commands:

python setup.py build_ext --inplace

This will take about 2 minutes. Once it is finished, run this command:

python setup.py build

This will also take about 2 minutes.

Test pandas

To make sure it has built properly, run the following command inside the pandas directory:

python

Within this python prompt, type:

 >>> import pandas
 >>> print pandas.__version__

You should see this version number: '''0.10.0b1'''. Done hope this rids you off the error .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM