csv档问题

楼主: blaga (blaga)   2021-03-24 15:50:59
各位前辈好,最近刚碰读取档案的问题,
老师出了一个简单的作业,
https://imgur.com/a/xMCzj0e
读取csv档将每一笔资料打印出来,但须对齐排列,爬了很多文,但我输出的结果都是如此
https://imgur.com/a/QCuVBQh
并且最后会多很多的逗号,想问各位前辈应该怎么修改程式码
import os
import csv
from io import TextIOWrapper
from io import BytesIO
import requests
import urllib
from urllib.request import urlretrieve # used to copy a network object to a loc
al file
url = 'https://datacenter.taichung.gov.tw/swagger/OpenData/6bb100e6-0f81-4e3a-8d
23-7fe16f929bf1'
urlretrieve(url, 'hw1_data.csv')
hw1_data.csv =
open('hw1_data.csv', 'r', encoding = 'utf-8-sig', newline = '') as csvfile:
plots = csv.reader(csvfile, delimiter = ':')
for row in plots:
print('%20s'%row[0])
csvfile.close()
作者: cuteSquirrel (松鼠)   2021-03-24 17:14:00
delimiter 应该放逗号,请留意CSV档案的格式
作者: zerof (猫橘毛发呆雕像)   2021-03-25 00:00:00
就空白行...滤掉就好

Links booklink

Contact Us: admin [ a t ] ucptt.com