pandas python 中没有名为 read_csv 的属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31752715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
no attribute named read_csv in pandas python
提问by Pragna Debnath
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:
我是机器学习的新手,正在使用 Python 中的 Pandas 创建数据集。我查了一个教程,只是尝试了一个用于创建数据框的基本代码,但我不断得到以下回溯:
AttributeError: 'module' object has no attribute 'read_csv'
AttributeError: 'module' 对象没有属性 'read_csv'
I have saved the csv file in the csv(comma delimited) formatfrom Excel 13. Here's my code:
我已经从 Excel 13 以 csv(逗号分隔)格式保存了 csv 文件。这是我的代码:
import pandas
import csv
mydata = pandas.read_csv('foo.csv')
target = mydata["Label"]
data = mydata.ix[:,:-1]
回答by Shovalt
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.
工作目录中有一个名为pandas.py(and/or pandas.pyc) 的文件,它是导入而不是 pandas 库的。删除或重命名文件解决了问题。
回答by Akash Kandpal
More likely you have not installed pandas correctly . For me installing pandas correctly got me through this error . Here goes the installation .....
更有可能是您没有正确安装 pandas。对我来说,正确安装 pandas 让我度过了这个错误。安装就到这里了.....
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).
这将安装一个快速数字处理库 (numpy) 和 Pandas 构建过程中所需的工具 (cython)。
Test numpy
测试 numpy
Open up a Python prompt by running the following:
通过运行以下命令打开 Python 提示符:
python
At the prompt, type the following:
在提示符下,键入以下内容:
>>> import numpy
>>> print numpy.__version__
You should see a number like "1.6.1" or higher.
您应该会看到类似“1.6.1”或更高的数字。
Test cython
测试cython
Open up a Python prompt by running the following:
通过运行以下命令打开 Python 提示符:
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.
您应该会看到类似“0.15.1”或更高的数字。
Download pandas
下载Pandas
We recommend storing pandas in a directory called ''projects'' in your user directory. To do that, run the following commands:
我们建议将 pandas 存储在用户目录中名为“projects”的目录中。为此,请运行以下命令:
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.
您将看到 git download pandas。下载完成后,您会收到提示,请继续下一步。
Build pandas
构建Pandas
To build pandas, you have to run the following two commands:
要构建Pandas,您必须运行以下两个命令:
python setup.py build_ext --inplace
This will take about 2 minutes. Once it is finished, run this command:
这将需要大约 2 分钟。完成后,运行以下命令:
python setup.py build
This will also take about 2 minutes.
这也将需要大约 2 分钟。
Test pandas
测试Pandas
To make sure it has built properly, run the following command inside the pandas directory:
要确保它已正确构建,请在 pandas 目录中运行以下命令:
python
Within this python prompt, type:
在此 python 提示中,键入:
>>> import pandas
>>> print pandas.__version__
You should see this version number: '''0.10.0b1'''. Done hope this rids you off the error .
你应该看到这个版本号:'''0.10.0b1'''。完成希望这可以消除您的错误。

