parent
e8785a87bb
commit
0e0721806b
@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Fri Apr 18 08:11:13 2025
|
||||
|
||||
@author: 缄默
|
||||
"""
|
||||
import csv
|
||||
|
||||
##################config###################
|
||||
trainDataPath = ["train1.csv","train2.csv"]
|
||||
###########################################
|
||||
|
||||
DataDic = {}
|
||||
def ReadFile():
|
||||
for path in trainDataPath:
|
||||
csvData = csv.reader(open(path))
|
||||
for row in list(csvData)[1:]:
|
||||
tmp = row[0].split('_')
|
||||
Idx,Speaker,Snt = tmp[1],tmp[-1],row[1]
|
||||
if Idx not in DataDic:
|
||||
DataDic.update({Idx:[]})
|
||||
DataDic[Idx].append(Speaker+' : '+Snt)
|
||||
#DataDic[Idx].append(Snt)
|
||||
|
||||
def Data2csv(path):
|
||||
with open(path, 'w', newline='', encoding='utf-8') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerows([["id","text"]])
|
||||
for key in DataDic.keys():
|
||||
length = len(DataDic[key])
|
||||
writer = csv.writer(f)
|
||||
writer.writerows([[key,"\n".join(DataDic[key])]])
|
||||
"""
|
||||
if(length<=3 or length>=10):
|
||||
pass
|
||||
else:
|
||||
writer = csv.writer(f)
|
||||
writer.writerows([[key,"\n".join(DataDic[key])]])
|
||||
"""
|
||||
|
||||
ReadFile()
|
||||
Data2csv('./output.csv')
|
||||
|
||||
|
Loading…
Reference in new issue