Python Pandas - 删除重复值的返回索引
要返回删除了重复值的索引,请使用该方法。index.drop_duplicates()
首先,导入所需的库-
import pandas as pd
创建具有一些重复项的索引-
index = pd.Index(['Car','Bike','Truck','Car','Airplane'])
显示索引-
print("Pandas Index with duplicates...\n",index)删除重复值的返回索引。默认情况下,它会删除第一次出现的重复值-
print("\nIndex with duplicate values removed...\n",index.drop_duplicates())示例
以下是代码-
import pandas as pd
#创建具有一些重复项的索引
index = pd.Index(['Car','Bike','Truck','Car','Airplane'])
#显示索引
print("Pandas Index with duplicates...\n",index)
#返回数据的dtype
print("\nThe dtype object...\n",index.dtype)
#获取数据中的字节
print("\nGet the bytes...\n",index.nbytes)
#获取数据的维度
print("\nGet the dimensions...\n",index.ndim)
#删除重复值的返回索引
#默认情况下,它会删除第一次出现的重复值
print("\nIndex with duplicate values removed...\n",index.drop_duplicates())输出结果这将产生以下代码-
Pandas Index with duplicates... Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane'], dtype='object') The dtype object... object Get the bytes... 40 Get the dimensions... 1 Index with duplicate values removed... Index(['Car', 'Bike', 'Truck', 'Airplane'], dtype='object')
热门推荐
10 教练生日祝福语 简短独特
11 修祖屋祝福语简短
12 理科元旦祝福语大全简短
13 发小结婚简短祝福语
14 职场祝福语大全 简短精辟
15 晚儿子生日祝福语简短
16 生日祝福语简短独特的
17 三十三句祝福语简短
18 公司上班祝福语大全简短