我正在通过ssh获取csv进行处理。
import csv
logging.info(csv_content)
for row in csv.reader(csv_content):
logging.info(row) # expecting [date, name, count]
已记录的行已被拆分为六次。不像其他时间我做过这个。
"2018-01-01 01","NAME1","1"
"2018-01-01 01","NAME2","55"
"2018-01-01 02","NAME1","2"
...
['2018-01-01 01']
['', '']
['NAME1']
['', '']
['1']
[]
['2018-01-01 01']
['', '']
['NAME2']
['', '']
['55']
[]
...
它必须是文件,不知何故。我玩过编码和csv参数,但它让我st脚。
我不能第一次遇到这个?
答案 0 :(得分:0)
csv.reader不想要csv_content。它想要csv文件。这是为了阅读每一行。
解决方法是在喂食读者之前分割线。
for row in csv.reader(csv_content.split("\n")):