当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python Pandas Index.is_unique用法及代码示例

Pandas 索引是一个不变的ndarray,它实现了有序的,可切片的集合。它是存储所有 Pandas 对象的轴标签的基本对象。

Pandas Index.is_unique属性返回True如果给定Index对象中的基础数据是唯一的,则返回False

用法: Index.is_unique

参数:没有

返回:布尔值

范例1:采用Index.is_unique属性以确定给定Index对象中的基础数据是否唯一。

# importing pandas as pd 
import pandas as pd 
  
# Creating the index 
idx = pd.Index(['Melbourne', 'Sanghai', 'Lisbon', 'Doha', 'Moscow']) 
  
# Print the index 
print(idx)

输出:

现在我们将使用Index.is_unique属性以确定给定Index对象中的基础数据是否唯一。

# check if the values in the Index 
# is unique or not. 
result = idx.is_unique 
  
# Print the result 
print(result)

输出:

正如我们在输出中看到的,Index.is_unique属性已返回True指示给定Index对象的基础数据是唯一的。

范例2:采用Index.is_unique属性以确定给定Index对象中的基础数据是否唯一。

# importing pandas as pd 
import pandas as pd 
  
# Creating the index 
idx = pd.Index([900, 700, 620, 388, 900]) 
  
# Print the index 
print(idx)

输出:

现在我们将使用Index.is_unique属性以确定给定Index对象中的基础数据是否唯一。

# check if the values in the Index 
# is unique or not. 
result = idx.is_unique 
  
# Print the result 
print(result)

输出:

正如我们在输出中看到的,Index.is_unique属性已返回False指示给定Index对象的基础数据不是唯一的。



相关用法


注:本文由纯净天空筛选整理自Shubham__Ranjan大神的英文原创作品 Python | Pandas Index.is_unique。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。