[Python]python对csv去除重复行 python 2020.2.11
用pandas库的.drop_duplicates函数
代码如下:
import shutil import pandas as pd frame=pd.read_csv(‘E:/bdbk.csv‘,engine=‘python‘) data = frame.drop_duplicates(subset=[‘名称‘], keep=‘first‘, inplace=False) data.to_csv(‘E:/baike.csv‘, encoding=‘utf8‘)
.drop_duplicates有三个参数
DataFrame.drop_duplicates(subset=None, keep=‘first‘, inplace=False)
如subset=[‘A‘,‘B‘]去A列和B列重复的数据
参数如下:
subset : column label or sequence of labels, optional
用来指定特定的列,默认所有列
keep : {‘first’, ‘last’, False}, default ‘first’
删除重复项并保留第一次出现的项
inplace : boolean, default False
是直接在原来数据上修改还是保留一个副本
相关推荐
夜斗不是神 2020-11-17
huavhuahua 2020-11-20
Yasin 2020-11-16
xiaoseyihe 2020-11-16
千锋 2020-11-15
diyanpython 2020-11-12
chunjiekid 2020-11-10
wordmhg 2020-11-06
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16