在SQL语言中去重是一件相当简单的事情,面对一个表(也可以称之为DataFrame)我们对数据进行去重只需要GROUP BY 就好。
select custId,applyNo from tmp.online_service_startloan group by custId,applyNo
1.DataFrame去重
但是对于pandas的DataFrame格式就比较麻烦,我看了其他博客优化了如下三种方案。
我们先引入数据集:
import pandas aspd
data=pd.read_csv(r'D:/home/nohup.out.20191028.startloan.csv',encoding='utf-8')print(data.info())
共有14936条数据,那我们还是按 custId和applyNo去重。
1.使用list后手写去重
定义去重函数:我这里使用了遍历行,添加列表的的方式去重。
#定义去重函数
defdropRep(df):
list2=[]for _,i indf.iterrows():