首页 > 代码库 > python合并多个csv文件并去重

python合并多个csv文件并去重

#coding=utf-8
import os
import pandas as pd
import glob

def hebing():
    csv_list = glob.glob(*.csv)
    print(u共发现%s个CSV文件% len(csv_list))
    print(u正在处理............)
    for i in csv_list:
        fr = open(i,r).read()
        with open(haha.csv,a) as f:
            f.write(fr)
    print(u合并完毕!)

def quchong(file):
    df = pd.read_csv(file,header=0)
    datalist = df.drop_duplicates()
    datalist.to_csv(file)

if __name__ == __main__:
    hebing()
    quchong("haha.csv")

 

python合并多个csv文件并去重