pandas python 熊猫索引 is_unique 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16304750/
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
python pandas index is_unique not working
提问by piRSquared
I'm new to python so please call me on not including relevant information.
我是 python 的新手,所以请打电话给我不包括相关信息。
I've installed python, ipython, and am using the notebook on an Ubuntu installation in a VM.
我已经安装了 python、ipython,并且正在 VM 中的 Ubuntu 安装上使用笔记本。
I'm working through examples laid out in Wes McKinney's Python for Data Analysis. After the following import statements:
我正在研究 Wes McKinney 的 Python for Data Analysis 中列出的示例。在以下导入语句之后:
from pandas import Series, DataFrame
import pandas as pd
I defined a dataframe with:
我定义了一个数据框:
series1 = Series(range(5), index=['a', 'a', 'b', 'b', 'c'])
And subsequently wanted to test the indexes uniqueness with:
随后想用以下方法测试索引的唯一性:
series1.index.is_unique
And get this error:
并得到这个错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/username/<ipython-input-64-e42615bb2da2> in <module>()
----> 1 series1.index.is_unique
AttributeError: 'Index' object has no attribute 'is_unique'
The book indicates this attribute exists. Other stackoverflow questions and answers reference this attribute.
该书表明此属性存在。其他 stackoverflow 问题和答案引用了此属性。
What am I doing wrong?
我究竟做错了什么?
Thanks
谢谢
After being asked what version of pandas I was using, I checked and it was 0.7.0 Upgrading with
在被问到我使用的是哪个版本的 Pandas 后,我检查了它是 0.7.0 Upgrading with
pip install --upgrade pandas
Got me where I needed to be.
把我带到我需要去的地方。
回答by Bryan
Make sure you are using an updated version, no issues here with 0.11.0:
确保您使用的是更新版本,这里没有问题0.11.0:
>>> from pandas import Series, DataFrame
>>> s = Series(range(5), index=['a', 'a', 'b', 'b', 'c'])
>>> s.index.is_unique
False
Either download the most recent version from here, or upgrade from command line:
从这里下载最新版本,或从命令行升级:
pip install --upgrade pandas
For this snippet there's no need to import pandas as pdon the second line, so I've removed it.
对于这个片段import pandas as pd,第二行不需要,所以我把它删除了。

