python如何读取csv文件列表页_如何用Python将CSV文件读入HTML表?

我需要从CSV文件中输入数据,并创建一个HTML表作为输出。

我目前的工作是:with open('2016motogp.csv') as csvfile:

reader = csv.DictReader(csvfile, delimiter='\t')

for row in reader:

print('

for fn in reader.fieldnames:

print('

{}'.format(row[fn]))

print('

')

当我运行这个函数时,我会得到一个错误:---------------------------------------------------------------------------

UnicodeDecodeError Traceback (most recent call last)

in ()

----> 1 write_html_table("2016motogp")

in write_html_table(filename)

55 with open(filename + ".csv") as csvfile:

56 reader = csv.DictReader(csvfile, delimiter='\t')

---> 57 for row in reader:

58 print('

59 for fn in reader.fieldnames:

E:\Anaconda\lib\csv.py in __next__(self)

109 if self.line_num == 0:

110 # Used only for its side effect.

--> 111 self.fieldnames

112 row = next(self.reader)

113 self.line_num = self.reader.line_num

E:\Anaconda\lib\csv.py in fieldnames(self)

96 if self._fieldnames is None:

97 try:

---> 98 self._fieldnames = next(self.reader)

99 except StopIteration:

100 pass

E:\Anaconda\lib\encodings\cp1252.py in decode(self, input, final)

21 class IncrementalDecoder(codecs.IncrementalDecoder):

22 def decode(self, input, final=False):

---> 23 return codecs.charmap_decode(input,self.errors,decoding_table)[0]

24

25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1037: character maps to

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值