#Reading from csv file
with open('py_csv/oscar_age_male.csv','r') as csv_file:
csv_reader=csv.reader(csv_file)
#Creating new file and opening it and changing delimiter
with open('py_csv/newfile.csv','w')as newfile:
csv_writer=csv.writer(newfile)
#Writing Row by row
for line in csv_reader:
csv_writer.writerow(line)
字符串
原始文件数据=
1, 1928, 44, "Emil Janning", "The Last Command, The Way of All Flesh"
2, 1929, 41, "Warner Baxter", "In Old Arizona"
型
复制后的数据=
1, 1928, 44," ""Emil Janning"""," ""The Last Command"," The Way of All Flesh"""
2, 1929, 41," ""Warner Baxter"""," ""In Old Arizona"""
型
1条答案
按热度按时间zvms9eto1#
问题是逗号后面的空格。CSV中允许在字段周围使用引号,但由于字段以空格开头,引号似乎不会包围整个字段值。因此它们被视为需要在输出中加倍的文字引号。
使用
skipinitialspace
选项忽略这些空格。字符串