import os import csv #合并,去重,进行筛选处理 out_fuile = '多抓鱼数据存档.csv' #文件合并 def merge_csv_files(files, output): for file1 in files: if '数据存档.csv' not in file1: continue with open(file1, 'r', newline='') as file1: reader1 = csv.reader(file1) with open(output, 'a', newline='',encoding="utf-8") as outfile: writer = csv.writer(outfile) for row in reader1: writer.writerow(row) outfile.close() def deduplicate_csv(input_file): file_list = [] file_list2 = [] with open(input_file, 'r',encoding='gbk') as file: reader = csv.reader(file) for row in reader: if float(row[2]) - float(row[3]) >= 30: continue if row[0] not in file_list: file_list.append(row[0]) file_list2.append(row) f = open(input_file, "w") f.close() with open(input_file, 'a', newline='', encoding="gbk") as outfile: writer = csv.writer(outfile) for row in file_list2: if len(row) < 10: continue writer.writerow(row) outfile.close() if __name__ == "__main__": #f = open(out_fuile, "w") #f.close() #file_name = os.listdir('.') #merge_csv_files(file_name, out_fuile) deduplicate_csv(out_fuile) # for i in file_name: # if '多抓鱼数据存档.csv' in i: # os.remove(i)