Để chỉ ra tất cả các giá trị chỉ mục trùng lặp là True, hãy sử dụng index.duplicated () . Sử dụng giữ lại tham số có giá trị Sai.
Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Tạo chỉ mục với một số bản sao -
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
Hiển thị chỉ mục -
print("Pandas Index with duplicates...\n",index) Cho biết tất cả các giá trị chỉ mục trùng lặp là True. Đặt thông số "keep" là "False" -
print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False)) Ví dụ
Sau đây là mã -
import pandas as pd
# Creating the index with some duplicates
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
# Display the index
print("Pandas Index with duplicates...\n",index)
# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)
# get the dimensions of the data
print("\nGet the dimensions...\n",index.ndim)
# Indicate all duplicate index values as True
# Set the "keep" parameter as "False"
print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False)) Đầu ra
Điều này sẽ tạo ra mã sau -
Pandas Index with duplicates... Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane'], dtype='object') The dtype object... object Get the dimensions... 1 Indicating all duplicate index values True... [False False True False True]