pythoncsv读取信用_CSV文件以Python读取

I have two type of csv's having data like:

Format 1 read from csv created from spreadsheet having two coloums.

datas = [[u'Woeoe;"ww@w.com"'], [u'wqqq;"Ww2@2.com"'], [u'Asasasa;"122@22.co.in"']]

format 2 read from the csv created from text editor save as .csv and having data like

fname lname,email@email.com

fname1 lname2 ,email@email1.com

datas = [[u'Vaada sasoe ', u'ssdoe@d.com'], [u'skdod asksd ', u'shashias@ssdsd.com']]

i have read those files with csv reader:

reader = csv.reader(input, quotechar='"', delimiter=',')

datas = []

for line in reader:

datas.append(line)

how do i handle those two different format output of csv reader ? is their any way that i can convert the data while reading in to one simple comma separated format like format2 mention above if i input the any type of csv ? basically i want to data read should be in always in format2.

解决方案

The first file use ";" as delimiter. So, you just have to say it to the reader.

Try to read the first file with csv.reader(input, quotechar='"', delimiter=';')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值