import pandas as pd

#生成数据
data1,data2,data3,data4=['a',3],['b',2],['a',3],['c',2]
df=pd.DataFrame([data1,data2,data3,data4],columns=['col1','col2'])
print(df)
col1 col2
0 a 3
1 b 2
2 a 3
3 c 2 #判断数据
isDuplicated=df.duplicated() #判断重复数据记录
print(isDuplicated)
0 False
1 False
2 True
3 False
dtype: bool #删除重复的数据
print(df.drop_duplicates()) #删除所有列值相同的记录,index为2的记录行被删除
col1 col2
0 a 3
1 b 2
3 c 2 print(df.drop_duplicates(['col1'])) #删除col1列值相同的记录,index为2的记录行被删除
col1 col2
0 a 3
1 b 2
3 c 2 print(df.drop_duplicates(['col2'])) #删除col2列值相同的记录,index为2和3的记录行被删除
col1 col2
0 a 3
1 b 2 print(df.drop_duplicates(['col1','col2'])) #删除指定列(col1和col2)值相同的记录,index为2的记录行被删除
col1 col2
0 a 3
1 b 2
3 c 2

Pandas重复值处理的更多相关文章

  1. [Python] Pandas 对数据进行查找、替换、筛选、排序、重复值和缺失值处理

    目录 1. 数据文件 2. 读数据 3. 查找数据 4. 替换数据 4.1 一对一替换 4.2 多对一替换 4.3 多对多替换 5. 插入数据 6. 删除数据 6.1 删除列 6.2 删除行 7. 处 ...

  2. Python数据分析中对重复值、缺失值、空格的处理

    对重复值的处理 把数据结构中,行相同的数据只保留一行 函数语法: drop_duplicates() from pandas import read_csv df = read_csv(文件位置) n ...

  3. pandas_处理异常值缺失值重复值数据差分

    # 处理异常值缺失值重复值数据差分 import pandas as pd import numpy as np import copy # 设置列对齐 pd.set_option("dis ...

  4. innodb 自增列重复值问题

    1 innodb 自增列出现重复值的问题 先从问题入手,重现下这个bug use test; drop table t1; create table t1(id int auto_increment, ...

  5. [LeetCode] Contains Duplicate III 包含重复值之三

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  6. [LeetCode] Contains Duplicate II 包含重复值之二

    Given an array of integers and an integer k, return true if and only if there are two distinct indic ...

  7. [LeetCode] Contains Duplicate 包含重复值

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  8. MySQL 处理插入过程中的主键唯一键重复值办法

    200 ? "200px" : this.width)!important;} --> 介绍 本篇文章主要介绍在插入数据到表中遇到键重复避免插入重复值的处理方法,主要涉及到I ...

  9. JS 数组去重复值

    var arr1 = [90, 91, 92]; var arr2 = [80, 81]; var arr3 = [80, 71, 72, 73]; var arr = arr1.concat(50, ...

随机推荐

  1. 使用php的curl函数post返回值为301永久迁移的问题。(301 Moved Permanently)

    本文链接:https://blog.csdn.net/Angus_01/article/details/82467652添加一行curl_setopt: curl_setopt($ch,CURLOPT ...

  2. VC2008中处理CStatic控件的单击STN_CLICKED消息

    在MFC中,静态文本CStatic控件主要是用来作为标签,即作为注释用的.一般情况下不做消息响应.但是有时特殊情况下会做一些消息响应,比如处理单击事件STN_CLICKED等. 在VC2008下使用M ...

  3. 实用的Python(2)利用Python制作gif动图

    一.简介 moviepy是一个专门用于视频剪辑制作的模块,可以自动化完成很多繁琐的视频剪辑处理工作,除了处理视频数据之外,moviepy中还内置了可以制作gif动图的功能,通过使用moviepy.ed ...

  4. 一个完整实用的axios封装

    1.先引入 import axios from 'axios' import qs from 'qs'import router from '../router'; import store from ...

  5. typescript 类型映射 (ReadOnly、Partial)

    有时候需要一个类型,是依赖于上一个类型但是,对属性的要求去不同 interface Person{ name: string; agent: number; } type Person2 = Read ...

  6. go之linux安装

    下载地址:https://golang.org/dl/ ubuntu16.04安装过程 官方安装文档:https://golang.org/doc/install?download=go1.11.4. ...

  7. enovia plm export to sap

    UPC creation UPC 结构 PLM 使用的UPC 是 14个数字组成的,兼容. 前两位为 0,后12位为有效数字,在SAP中0会被忽略,符合国际UPC通用 规则, 前一位为0,后13 位为 ...

  8. 2018-8-10-win10-uwp-json

    title author date CreateTime categories win10 uwp json lindexi 2018-08-10 19:16:53 +0800 2018-2-13 1 ...

  9. JDK安装的一些设置

    一:设置环境变量 1.新建环境变量JAVA_HOME值为JDK安装目录   然后编辑Path环境变量添加".%JAVA_HOME%\bin;". Ps:JDK5.0不需要设置cla ...

  10. ie 图片拉伸

    终于发现只要设置img为 height:auto,width:auto,就不会出现这种情况了 img { height: auto; width: auto; }