python将多个csv合并为一个_如何使用Python2.7将多个csv列合并到一个列中?

我正在处理大量的csv数据,我想把不同位置的几列放入一列中,用分号(;)分隔。在

所以我现在的情况是。。在a b c d

1 2 3 4

1 2 3 4

1 2 3 4

我想把它改成…这个,所以我所有的数据都只在d列

^{pr2}$

我知道如何删除这些空列a、b和c,但我无法找到将a、b、c列中的数据合并到d列中的方法。

提前谢谢。在

到目前为止我得到的代码是。。在# Parsing the custom formatted data with csv module.

# reads the custom format input and spits out the output in VCF format.

import csv

# input and output

with open('1-0002', 'rb') as csvin, open('converted1','wb') as csvout:

# reading and writing are all tab delimited

reader = csv.reader(csvin, delimiter = '\t')

writer = csv.writer(csvout, delimiter = '\t')

# add headings before the for loop to prevent the heading being affected by column manipulation.

writer.writerow(["#CHROM","POS","ID","REF","ALT","QUAL","FILTER","INFO"])

for row in reader:

# deleting unnecessary columns, 'del' operator must be in ascending order or else it will give range error

# manually deleting columns since the input data is in custom format.

del row[11]

del row[10]

del row[9]

del row[8]

del row[7]

del row[6]

del row[5]

del row[1]

del row[0]

# inserting 1 and . in specific columns

row.insert(0,'1')

row.insert(2,'.')

row.insert(5,'.')

row.insert(7,'') # inserting empty column for INFO headings.

# change 'YES' to 'PASS' , leaving HETERO as it is.

if row[6] == 'YES':

row[6] = 'PASS'

writer.writerow(row)

所以从上面的代码中,我想把来自不同列的数据放入INFO列中。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值