Python Pandas - 檢查索引是否具有唯一值
如需檢查索引是否具有唯一值,請使用index.is_unique。
首先,匯入所需的庫 −
import pandas as pd
讓我們建立索引 −
index = pd.Index([50, 40, 30, 20, 10])
顯示索引 −
print("Pandas Index...\n",index)檢查索引是否具有唯一值 −
print("\nIs the Pandas index having unique values?\n",index.is_unique)
示例
以下是程式碼 −
import pandas as pd
# Creating the index
index = pd.Index([50, 40, 30, 20, 10])
# Display the index
print("Pandas Index...\n",index)
# Return an array representing the data in the Index
print("\nArray...\n",index.values)
# Check if the index is having unique values
print("\nIs the Pandas index having unique values?\n",index.is_unique)輸出
這將生成以下程式碼 −
Pandas Index... Int64Index([50, 40, 30, 20, 10], dtype='int64') Array... [50 40 30 20 10] Is the Pandas index having unique values? True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP