You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
# -*- 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')
|
|
|
|
|