为什么下面的项目失败了?为什么它成功与“拉丁-1”编解码器?
o = "a test of \xe9 char" #I want this to remain a string as this is what I am receiving
v = o.decode("utf-8")
结果是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\encodings\utf_8.py",
line 16, in decode
return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError:
'utf8' codec can't decode byte 0xe9 in position 10: invalid continuation byte
当你在pandas中输入一个特定的文件或数据时,这种类型的错误就会出现:-
data=pd.read_csv('/kaggle/input/fertilizers-by-product-fao/FertilizersProduct.csv)
错误显示如下:-
UnicodeDecodeError: 'utf-8' codec不能解码字节0xf4在位置1:无效的延续字节
因此,为了避免这种类型的错误,可以通过添加参数来删除
data=pd.read_csv('/kaggle/input/fertilizers-by-product-fao/FertilizersProduct.csv', encoding='ISO-8859-1')
在这种情况下,我尝试执行一个激活路径/file.sql的.py。
我的解决方案是修改文件的编码。sql到“UTF-8没有BOM”,它的工作!
你可以用notepad++来做。
我会留下一部分代码。
con = psycopg2.connect(host = sys.argv[1],
port = sys.argv[2],dbname = sys.argv[3],user = sys.argv[4], password = sys.argv[5])
cursor = con.cursor()
sqlfile = open(path, 'r')
当你在pandas中输入一个特定的文件或数据时,这种类型的错误就会出现:-
data=pd.read_csv('/kaggle/input/fertilizers-by-product-fao/FertilizersProduct.csv)
错误显示如下:-
UnicodeDecodeError: 'utf-8' codec不能解码字节0xf4在位置1:无效的延续字节
因此,为了避免这种类型的错误,可以通过添加参数来删除
data=pd.read_csv('/kaggle/input/fertilizers-by-product-fao/FertilizersProduct.csv', encoding='ISO-8859-1')