no attribute named read_csv in pandas python

白昼怎懂夜的黑 提交于 2019-12-23 07:38:21

问题


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]

回答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.




回答2:


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 .



来源:https://stackoverflow.com/questions/31752715/no-attribute-named-read-csv-in-pandas-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!