导入pandas模块提供属性错误 [英] Import pandas module gives Attribute Error

查看:312
本文介绍了导入pandas模块提供属性错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从Windows更改为Ubuntu 12.04 LTS,我试图抓住Python。

I recently changed from Windows to Ubuntu 12.04 LTS, and I am trying to get the hang on Python.

我从$ b $复制了几个示例命令b http://pandas.pydata.org/pandas-docs/stable/10min。 html
到一个名为pandas.py的.py文件中

I copied a couple of example commands from http://pandas.pydata.org/pandas-docs/stable/10min.html into a .py file called pandas.py

这个文件是在我的主目录/ home / myname中创建的

This file was created in my home directory /home/myname

以下是/home/myname/pandas.py前14行的摘录:

Here is an excerpt with the first 14 lines of /home/myname/pandas.py:

# pandas.py

###################################
## Testing out the pandas module ##
## Last update: Jan 2014         ##
## Author: me                    ##
###################################

import pandas as pd
import numpy as np

# Creating a Series by passing a list of values,
# letting pandas create a default integer index
s = pd.Series([1,3,5,np.nan,6,8])

尝试运行脚本(使用IDLE),我收到以下消息:

when trying to run the script (using IDLE), I get the following message:

Traceback (most recent call last):
  File "/home/myname/mypandas.py", line 9, in <module>
    import pandas as pd
  File "/home/myname/pandas.py", line 14, in <module>
AttributeError: 'module' object has no attribute 'Series'

它看起来好像是Python试图导入我的.py文件而不是实际的模块。

it appears as if Python tried to import my .py file rather that the actual module.

如果我写的话会出现同样的错误

The same error appears if I write

import pandas

。我将文件名更改为mypandas.py,删除了以前的文件,清除了垃圾箱,然后重新启动。这个错误一直在出现。

on my Python Shell. I changed the file name to mypandas.py, deleted the previous file, cleared the trash bin, and rebooted. This error just keeps appearing.

其他库如numpy import就好了。我想有一些shell命令可以恢复这种情况,但我仍然不太熟悉Ubuntu。我该如何解决这个问题?

Other libraries such as numpy import just fine. I imagine there is some shell command which reverts this situation, but I am still not quite acquainted to Ubuntu. How can I fix this?

提前致谢

推荐答案

删除编译脚本, pandas.pyc ,来自您的主目录的脚本位置。并且不要将脚本命名为与您正在使用的模块相同的名称。

Delete compiled script, pandas.pyc, from the location of your script, that is from your home directory. And don't name your scripts the same names as modules you're using.

这篇关于导入pandas模块提供属性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆