我有一个CSV
文件,最后有100,000行,行将被插入MS-SQL
数据库。
问题是字段“auto_make”将在名称中包含逗号。
如何阅读将"auto_make"
字段中的逗号接受的csv文件?
autodata.csv
lot_date,sale_date,auto_make, vin<br>
2014-09-15 00:00:00,2014-09-15 15:12:13,Ford F250,be48a3a6-ba04-4df2-b07d-ab5b8b2f5351<br>
2014-09-15 00:00:00,2014-09-15 15:14:18,**Ford,Superduty**,0c1a7358-dd51-4db7-9632-993b050ac74c<br>
2014-09-15 00:00:00,2014-09-15 15:14:25,**Dodge,Charger,RT**,ac642530-6fcf-4f28-a075-62e12bbf7117<br>
结果字段应如下:
lot_date = 2014-09-15 00:00:00 sale_date = 2014-09-15 15:12:13 auto_make = Ford F250 vin = be48a3a6-ba04-4df2-b07d-ab5b8b2f5351<br>
lot_date = 2014-09-15 00:00:00 sale_date = 2014-09-15 15:14:18 auto_make = Ford,Superduty vin = 0c1a7358-dd51-4db7-9632-993b050ac74c<br>
lot_date = 2014-09-15 00:00:00 sale_date = 2014-09-15 15:14:25 auto_make = Dodge,Charger,RT vin = ac642530-6fcf-4f28-a075-62e12bbf7117<br>
感谢。
答案 0 :(得分:0)
假设您以字符串形式阅读每一行,以下内容将起作用:
line = "2014-09-15 00:00:00,2014-09-15 15:14:18,Ford,Superduty,0c1a7358-dd51-4db7-9632-993b050ac74c"
line_list = line.split(',')
lot_date = line_list[0]
sale_date = line_list[1]
auto_make = line_list[2:-1]
vin = line_list[-1]