我有一个 .csv 文件,例如:
ID NAME CATEGORIES
1, x, AB
2, xx, AA
3, xxx, BA
我将如何根据类别形成两个输出 .csv 文件,例如:
文件 1:
ID NAME CATEGORY
1, x, A
2, xx, A
3, xxx, B
文件 2:
ID NAME CATEGORY
1, x, B
2, xx, A
3, xxx, A
我已经设置了输入和输出,但只是一个空的 for 循环,我被难住了:
records = [line for line in csv.reader(open('test_input.csv', 'rt'), delimiter=',')]
outfile = open('test_output1.csv', 'wt')
outfileWriter = csv.writer(outfile, delimiter=',')
for record in records:
#something!
outfileWriter.writerow(record)
outfile.close()
我会很感激任何帮助!