检查 python panda 数据结构中的重复项 [英] Check for duplicates in a python panda data structure

查看:52
本文介绍了检查 python panda 数据结构中的重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 csv 文件.它看起来像这样;

I have a csv file. It looks something like this;

name,id,
AAA,1111,
BBB,2222,
CCC,3333,
DDD,2222,

我想提取 id 列中的数据并放置在数据结构中.为此,我使用了 python 熊猫.这是执行此操作的代码;

I would like to extract the data in id column and placed inside a data structure. For this, I used python panda. Here is the code for doing this;

import pandas as pd
csv_file = 'C:/test.csv'
df = pd.read_csv(csv_file)
column_items = df['id']

我想检查 id 列中的数据项之间是否存在重复项.数据项存储在column_items 中.在这种情况下,存在重复.

I would like to check whether there is a duplicate among the data items in the id column. The data items are stored in column_items. In this case, there is a duplicate.

我使用的是 python 2.7 和 panda 库.

I am using python 2.7 and panda library.

推荐答案

要找出整列中是否有重复的 ID,请执行

To find out whether there are duplicate IDs in that whole column, do

df['id'].duplicated().any()

这篇关于检查 python panda 数据结构中的重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆