geopandas读取文件编码错误:UnicodeDecodeError

错误情况

使用geopandas读取文件出现编码错误,代码如下:

import geopandas as gpd

# 指定 Shapefile 的路径
file_path = './gis/主干管.shp'

# 读取 Shapefile
data = gpd.read_file(file_path)

错误情况大致如下图:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef : unexpected end of data

解决办法

查了资料,这是读入文件时没有使用正确的编码去解析shp文件,根据文件内容调整编码,问题解决,以我碰到的问题为例:

import geopandas as gpd

# 指定 Shapefile 的路径
file_path = './gis/主干管.shp'

# 读取 Shapefile
data = gpd.read_file(file_path, encoding='gb18030')

猜你喜欢

转载自blog.csdn.net/Humbunklung/article/details/141270762