我有一个由我的客户生成的CSV文件,每行都是一堆行,如:
81.20414497158737,172.9103317265073,95.21067544500737,158.57147044650964,-84.25709905588982,-63.29849243164,-82.75973199495726,-61.30949985476218,-63.29849243164,-59.267658616873035,
注意每行末尾的,
,然后是回车符。
问题是当我在python中读取它时会生成一个额外的空白列。所以,我把它读作:
import csv
path = "path-to-file.csv"
with open(path) as f:
csv_file = csv.reader(f, delimiter=',')
for row in csv_file:
print(row)
这会将示例行打印为:
['81.91382020661584', '172.6194974551915', '95.000737839972', '157.5919980874564', '-83.09440263458094', '-63.29849243164', '-82.28324366654695', '-61.65345112997187', '-63.29849243164', '-57.6629400774182', '']
请注意末尾的额外空白列。
有没有办法使用python CSV阅读器解决这个问题?