# 使用 Python 实现数据去重(Distinct)
在编程中,我们经常需要对一组数据进行去重(distinct),尤其是在处理列表或数据库查询时。本文将教会你如何使用 Python 来实现这一功能。为此,我们将经过以下几个步骤:
| 步骤 | 描述                                    |
|------|-------------------------            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2024-10-05 05:33:34
                            
                                21阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            在pandas库中实现Excel的数据透视表效果通常用的是df['a'].value_counts()这个函数,表示统计数据框(DataFrame) df的列a各个元素的出现次数;例如对于一个数据表如pd.DataFrame({'a':['A','A','B','C','C','C'],'b':[1,2,3,4,5,6],'c':[11,11,12,13,13,14]}),其透视表效果如下:Exc            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2023-11-29 21:21:28
                            
                                239阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            Select:和SQL命令中的select作用相似但位置不同,查询表达式中的select及所接子句是放在表达式最后并把子句中的变量也就是结果返回回来;延迟.
Select/Distinct操作包括9种形式,分别为简单形式、匿名类型形式、带条件形式、指定类型形式、过滤类型形式、shaped类型形式、嵌套类型形式、LocalMethodCall形式、Distinct            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2024-05-18 06:35:32
                            
                                54阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            import pymongoclient = pymongo.MongoClient('192.168.0.136',27017) db = client.fangjia_statcl=db.rent_average_lg1013.distinct("city")ll=list(cl)print(ll)            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2023-01-13 00:26:35
                            
                                95阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            一、记录要点1.select <列名><列名> from <表名>2.*可以代表所有列3.用as 设置别名,如select 姓名 as s_name, 姓名 as '人类性别' from student4.distinct(用来删除一列中的重复数据),单列之前,是select distinct 姓名 from student,多列之前,组合相同才删除重点注意:列            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2024-05-29 06:01:17
                            
                                156阅读
                            
                                                                             
                 
                
                                
                     
                                    
                             
         
            
            
            
            背景 为什么需要调优?? 程序都是能跑的,集群还是那个集群,但是有可能另外一个会调优的人和你写的代码的运行的速度要几倍甚至几十倍1.开发调优1.1 原则一:避免创建重复的RDD我们有一份数据 ,student.txt 第一个需求 :wordCount val stuRDD = sc.textFile(“e://sparkData//student.txt”) 第二个需求:算有多少个学生 val s            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2024-06-21 09:18:38
                            
                                157阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            首先对于MySQL的DISTINCT的关键字的一些用法:1.在count 不重复的记录的时候能用到,比如SELECT COUNT( DISTINCT id ) FROM tablename;就是计算talbebname表中id不同的记录有多少条。2,在需要返回记录不同的id的具体值的时候可以用,比如SELECT DISTINCT id FROM tablename;返回talbebname表中不同            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2024-01-21 06:27:42
                            
                                60阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            PostgreSQL WITH 子句在 PostgreSQL 中,WITH 子句提供了一种编写辅助语句的方法,以便在更大的查询中使用。 WITH 子句有助于将复杂的大型查询分解为更简单的表单,便于阅读。 这些语句通常称为通用表表达式,也可当做一个为查询而存在的临时表。 通用表表达式:Common Table Express, CTE WITH 子句是在多次执行子查询时特别有用,允许我们在查询中通过            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2024-03-19 20:11:46
                            
                                33阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            数据表查询时,需要对重复结果筛选,去掉重复项。SQL SERVER:select distinct '列名'  from '表名';备注:DISTINCT 必须写在列名之前。            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2017-06-25 08:50:33
                            
                                590阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            SQL DISTINCT 的作用就是用来返回唯一不同的值。在工作中,我们常常会碰到某些表会有重复的值,而我们因业务需求却仅需要唯一值的数据报表,此时就会用到distinct来过滤了SQL DISTINCT 语法SELECT  DISTINCT  列名称 FROM  表名称举例:用SELECT查询表中"city"列的数据如下:SELECT city FROM Users;"User"表:从结果来看,            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2021-02-27 20:31:07
                            
                                440阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            QUESTION Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is form            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2022-01-12 10:54:18
                            
                                74阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none)            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2022-01-17 17:12:15
                            
                                76阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            rea             
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2023-02-17 01:06:03
                            
                                64阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            distinct可以列出不重复的记录,对于单个字段来说distinct使用比较简单,但是对于多个字段来说,distinct使用起来会使人发狂。而且貌似也没有见到微软对distinct使用多字段的任何说明。下面就提供了一种方法可以在使用distinct的时候同时使用多个字段。select 要使用字段1...            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2014-06-26 10:12:00
                            
                                132阅读
                            
                                                                                    
                                2评论
                            
                                                 
                 
                
                             
         
            
            
            
            Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from t            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2016-07-16 11:39:00
                            
                                157阅读
                            
                                                                                    
                                2评论
                            
                                                 
                 
                
                             
         
            
            
            
            Dynamic ProgrammingGiven a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is f...            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2014-11-24 08:53:00
                            
                                75阅读
                            
                                                                                    
                                2评论
                            
                                                 
                 
                
                             
         
            
            
            
            ## Java distinct()实现步骤
### 1. 创建一个List集合
首先,我们需要创建一个包含重复元素的List集合,用于演示distinct()方法的使用。
```java
List list = Arrays.asList("apple", "banana", "apple", "orange", "banana");
```
### 2. 使用Stream流进行去重操作            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2023-07-21 05:33:40
                            
                                462阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            大多数情况下,Distinct函数都会导致对最终结果集完成一次排序,因此,这就成为成本最昂贵的排序之一。Distinct一直是SQL语言中成本最高的函数之一。不过,对于DB2 V9,优化工具会尽量利用索引来消除为确定唯一性所带来的排序,其方法类似于目前用Group By语句完成优化时的做法。不过,实际上不必在SQL中使用Distinct,完全可以使用其他方式重写查询来得到同样的结果,这样做往往更为            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2024-08-16 10:31:59
                            
                                66阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            Oracle——distinct的用法 
 下面先来看看例子:table表字段1     字段2   id        name   1                     
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2023-08-09 16:33:20
                            
                                81阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,"ACE"            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2013-09-12 11:57:00
                            
                                117阅读
                            
                                                                                    
                                2评论