Pandas重复值处理
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重复值处理的更多相关文章
- [Python] Pandas 对数据进行查找、替换、筛选、排序、重复值和缺失值处理
目录 1. 数据文件 2. 读数据 3. 查找数据 4. 替换数据 4.1 一对一替换 4.2 多对一替换 4.3 多对多替换 5. 插入数据 6. 删除数据 6.1 删除列 6.2 删除行 7. 处 ...
- Python数据分析中对重复值、缺失值、空格的处理
对重复值的处理 把数据结构中,行相同的数据只保留一行 函数语法: drop_duplicates() from pandas import read_csv df = read_csv(文件位置) n ...
- pandas_处理异常值缺失值重复值数据差分
# 处理异常值缺失值重复值数据差分 import pandas as pd import numpy as np import copy # 设置列对齐 pd.set_option("dis ...
- innodb 自增列重复值问题
1 innodb 自增列出现重复值的问题 先从问题入手,重现下这个bug use test; drop table t1; create table t1(id int auto_increment, ...
- [LeetCode] Contains Duplicate III 包含重复值之三
Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...
- [LeetCode] Contains Duplicate II 包含重复值之二
Given an array of integers and an integer k, return true if and only if there are two distinct indic ...
- [LeetCode] Contains Duplicate 包含重复值
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- MySQL 处理插入过程中的主键唯一键重复值办法
200 ? "200px" : this.width)!important;} --> 介绍 本篇文章主要介绍在插入数据到表中遇到键重复避免插入重复值的处理方法,主要涉及到I ...
- JS 数组去重复值
var arr1 = [90, 91, 92]; var arr2 = [80, 81]; var arr3 = [80, 71, 72, 73]; var arr = arr1.concat(50, ...
随机推荐
- %matplotlib inline 被注释掉后,pycharm不能生成图
目录 问题描述 解决方案 @ 问题描述 在 jupyter 编译器中 程序的开头,有这么一行 %matplotlib inline import numpy as np import matplotl ...
- 25. Postman的使用
Postman下载与安装 不管是接口测试人员还是开发人员大概率下都绕不开一个工具,那就是Postman.当然可能还有一些接口测试工具,比如soapUI.Jmeter.Robot Framework 等 ...
- Jlink 接口定义
JTAG有10pin的.14pin的和20pin的,尽管引脚数和引脚的排列顺序不同,但是其中有一些引脚是一样的,各个引脚的定义如下. 1. 引脚定义 Test Clock Input (TCK) -- ...
- activi7流程部署
package com.zcc.acvitivi; import org.activiti.engine.ProcessEngine;import org.activiti.engine.Proces ...
- Java输入/输出教程
Java输入/输出(I/O)处理从源读取数据并将数据写入目标.通常,读取存储在文件中的数据或使用I/O将数据写入到文件中. java.io和java.nio包中包含处理输入/输出的Java类.java ...
- nginx 配置反向代理和静态资源
https://unit.nginx.org/integration/ 与NGINX集成 在NGINX后面安装单元 将NGINX配置为静态Web服务器,并在Unit前面配置反向代理. NGINX直接从 ...
- 常用命令--awk
awk '{ BEGIN{stat1} BEGIN{stat2} pattern1{action1} pattern2{action2} ... patternn{actionn} {默认动作,无条件 ...
- Oracle日志查看
一.Oracle日志的路径: 登录:sqlplus "/as sysdba" 查看路径:SQL> select * from v$logfile; SQL> selec ...
- python基础之基础数据类型1
int 整形 数字用于计算和比较 python3没有long,python2有整形和长整型 十进制二进制转换方法 bin(10进制) ==二进制 0b(二进制) int("二进制" ...
- kmp与扩展kmp模板
kmp 1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include & ...