gpt4 book ai didi

python - 获取“cp950”编解码器的Unicode解码错误,无法解码位置2516中的字节0x80:非法的多字节序列

转载 作者:行者123 更新时间:2023-12-03 17:56:07 30 4
gpt4 key购买 nike

我想读取CSV文件调用testing.csv,然后使用Python将其导入到SQLite数据库中。

但是,出现错误
enter image description here

这是Python代码:

import csv, sqlite3

con= sqlite3.connect('my_dataset.db')
cur = con.cursor()
cur.execute("CREATE TABLE t(aa,bb,cc,dd);")

with open('testing.csv','r') as fin:
dr = csv.DictReader(fin)
to_db = [(i['aa'], i['bb'],i['cc'],i['dd']) for i in dr]

cur.executemany("INSERT INTO t(aa,bb,cc,dd) VALUES (?,?,?,?);", to_db)
con.commit()
con.close()


这是CSV文件:
enter image description here

此外,我还想获取每行的平均值,最大值和最小值。我应该使用SQL关键字(AVG,MAX,MIN)还是其他方式?任何想法?我应该放在哪里?

谢谢〜

最佳答案

将您的csv解码为utf-8

为此,请更改:

with open('testing.csv','r') as fin:



with open('testing.csv','r', encoding='utf-8') as fin:

关于python - 获取“cp950”编解码器的Unicode解码错误,无法解码位置2516中的字节0x80:非法的多字节序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59076965/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com