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. 【单例模式】懒汉式的线程安全问题 volatile的作用

    原文链接:https://blog.csdn.net/Activity_Time/article/details/96496579 ****** 1. 懒汉式的Java实现 public class ...

  2. python学习笔记:函数

    一.函数是什么 函数一词来源于数学,但编程中的「函数」概念,与数学中的函数是有很大不同的,编程中的函数在英文中也有很多不同的叫法.在BASIC中叫做subroutine(子过程或子程序),在Pasca ...

  3. Java的部分问题和小结

    2015/9/6 ThreadLocal:该类提供了线程局部变量,这样可以生成对每个线程唯一的局部标识符. 2015/9/18 1.乱码问题:  js:xdata = encodeURI(encode ...

  4. window 下总是object_detection/protos/*.proto: No such file or directory

    这是因为目前的protoc3.5有Bug,换成3.4就好了https://github.com/google/protobuf/releases/tag/v3.4.0

  5. Apache Hadoop集群离线安装部署(二)——Spark-2.1.0 on Yarn安装

    Apache Hadoop集群离线安装部署(一)——Hadoop(HDFS.YARN.MR)安装:http://www.cnblogs.com/pojishou/p/6366542.html Apac ...

  6. 请问如何实现字符串UTF8->BIG5,BIG5->UTF8。保证送分。-Java/JavaSE

    请问如何实现字符串UTF8-> BIG5,BIG5-> UTF8. ------回答--------- ------其他回答(100分)--------- public String BI ...

  7. cd 切换

    切换

  8. 第2篇Kubernetes架构

      一.Kubernetes 架构: Kubernetes Cluster 由 Master 和 Node 组成,节点上运行着若干 Kubernetes 服务. Master 节点 Master 是 ...

  9. org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplic

    org.springframework.context.ApplicationContextException: Unable to start web server; nested exceptio ...

  10. 关系型数据库---MYSQL---系统学习

    1.概述 1.1 mysql数据库是一种  客户端/服务器体系  的 数据库系统: 服务器部分 在启动运行后没有人机界面,所以终端用户  无法直接使用MySQL: 对MySQL数据库进行访问.操作  ...