【发布时间】:2014-11-06 22:10:00
【问题描述】:
我正在尝试在 python3 中将两个单元格合并在一起。如有任何意见,我将不胜感激。
这是我的脚本的一部分:
with open(input) as infile, open (output, 'w') as outfile:
reader = csv.reader(infile, delimiter='\t')
writer = csv.writer(outfile, delimiter='\t')
for gg, poss, codee, ref, alt, *rest in reader:
gg = int(gg)
poss = int(poss)
writer.writerow([gg, poss, codee, d[group][poss-1], "ref+alt"] + rest)
我试图让列“ref”与“alt”合并(最后一行中的“ref+alt”),所以我的列将包含列“gg”、“poss”、“codee”、“ d[group][poss-3]”和“ref”+“alt”。
“ref”列如下所示:
A
B
C
而“alt”列有多个用逗号分隔的字母:
A,B
C,D,H
B,F,S
写最后一行以便“ref”和“alt”像这样合并的正确方法是什么?
A,A,B
B,C,D,H
C,B,F,S
【问题讨论】:
标签: python csv python-3.x