Python Pandas - 将所有重复的索引值指示为 True
要将所有重复的索引值指示为True,请使用.使用值为False的keep参数。index.duplicated()
首先,导入所需的库-
import pandas as pd
创建具有一些重复项的索引-
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
显示索引-
print("Pandas Index with duplicates...\n",index)将所有重复的索引值指示为True。将“保持”参数设置为“假”-
print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False))示例
以下是代码-
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)
#IndicateallduplicateindexvaluesasTrue
# Set the "keep" 参数为 "False"
print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False))输出结果这将产生以下代码-
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]
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短