Python Pandas - 指示除最后一次出现之外的重复索引值
要指示除最后一次出现之外的重复索引值,请使用.使用值为last的keep参数。index.duplicated()
首先,导入所需的库-
import pandas as pd
创建具有一些重复项的索引-
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
显示索引-
print("Pandas Index with duplicates...\n",index)将重复的索引值指示为True,但最后一次出现除外。将“keep”参数设置为“last”-
print("\nIndicating duplicate values except the last occurrence...\n", index.duplicated(keep='last'))示例
以下是代码-
import pandas as pd
#Creatingtheindexwithsomeduplicates
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
#Displaytheindex
print("Pandas Index with duplicates...\n",index)
#Returnthedtypeofthedata
print("\nThe dtype object...\n",index.dtype)
#getthedimensionsofthedata
print("\nGet the dimensions...\n",index.ndim)
#IndicateduplicateindexvaluesasTrue,exceptthelastoccurrence
# Set the "keep" 参数为 "last"
print("\nIndicating duplicate values except the last occurrence...\n", index.duplicated(keep='last'))输出结果这将产生以下代码-
Pandas Index with duplicates... Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane'], dtype='object') The dtype object... object Get the dimensions... 1 Indicating duplicate values except the last occurrence... [False False True False False]
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练