【问题标题】:UnicodeDecodeError 'utf-8' codec can't decode - using python shapefile readerUnicodeDecodeError 'utf-8' 编解码器无法解码 - 使用 python shapefile 阅读器
【发布时间】:2020-01-21 17:36:15
【问题描述】:

我正在尝试读取 shapefile

r = shapefile.Reader(filepath, encoding = "utf-8")

但是当我尝试从 .records() 对象中获取值时,例如:

 r.records()[0]

它返回给我以下错误:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 4: invalid continuation byte

【问题讨论】:

    标签: python unicode shapefile


    【解决方案1】:

    这意味着您的文件未以 utf-8 编码。尝试:ISO8859-1

    如果您在 Linux 上(或在 Windows 上使用 git-bash),您可以使用 file 命令找出编码。

    【讨论】:

    • 切换到 8 位编码可能只会消除症状,只会产生垃圾输出。您应该查看有问题的输入并确定它们使用的精确编码。如果\xE9 字节代表一个‘é’字符,Latin-1 或 CP1252 是很好的猜测;如果没有,也许看看tripleee.github.io/8bit/#e9 的其他解释。
    • @tripleee 或使用file 我建议检测编码
    • 精度不高。如果您只有几个字节并且知道或可以猜测它们代表什么字符,那可能会更准确。 file 在这种情况下会胡乱猜测。
    • 哈哈哈@JoelFan 一个 shapefile 描述了一个地理多边形,它广泛用于人口普查数据:p
    猜你喜欢
    • 2018-05-05
    • 1970-01-01
    • 2017-09-27
    • 2014-08-29
    • 2020-07-17
    • 2021-12-06
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    相关资源
    最近更新 更多