geodataframe.to_file 字段类型 <class 'bytes'> 无效

Bra*_*res 8 python fiona geopandas

我正在处理 shp 文件,并且在将地理数据帧保存在 shp 文件中时遇到问题。

import pandas as pd
import numpy as np
import os
import geopandas
location = '/home/braulio/Documents/example.shp'
datos = geopandas.read_file(location, encoding='UTF-8')
Run Code Online (Sandbox Code Playgroud)

我处理数据没有问题,但是当我尝试保存时

A.to_file(r"/home/braulio/Documents/example2.shp")
Run Code Online (Sandbox Code Playgroud)

并返回错误:

ValueError                                Traceback (most recent call last)
<ipython-input-23-6a842789b4b4> in <module>
----> 1 A.to_file(r"/home/braulio/Documents/example2.shp")

~/anaconda3/envs/braulio/lib/python3.7/site-   packages/geopandas/geodataframe.py in to_file(self, filename, driver,   schema, **kwargs)
411         """
412         from geopandas.io.file import to_file
--> 413         to_file(self, filename, driver, schema, **kwargs)
414 
415     def to_crs(self, crs=None, epsg=None, inplace=False):

~/anaconda3/envs/braulio/lib/python3.7/site-packages/geopandas/io/file.py in to_file(df, filename, driver, schema,**kwargs)
109         with fiona.open(filename, 'w', driver=driver, crs=df.crs,
110                         schema=schema, **kwargs) as colxn:
--> 111             colxn.writerecords(df.iterfeatures())
112 
113 

~/anaconda3/envs/braulio/lib/python3.7/site-packages/fiona/collection.py in writerecords(self, records)
347         if self.mode not in ('a', 'w'):
348             raise IOError("collection not open for writing")
--> 349         self.session.writerecs(records, self)
350         self._len = self.session.get_length()
351         self._bounds = self.session.get_extent()

fiona/ogrext.pyx in fiona.ogrext.WritingSession.writerecs()

fiona/ogrext.pyx in fiona.ogrext.OGRFeatureBuilder.build()

ValueError: Invalid field type <class 'bytes'>
Run Code Online (Sandbox Code Playgroud)

Wal*_*han 6

“字节”和某些其他类型(例如“列表”)不是 shapefile 支持的数据类型。这是讨论此问题的 github 问题的链接。

我建议删除具有“字节”类型对象的列,然后保存形状文件。

如果该列确实很重要,请将值更改为“字符串”类型,然后保存 shapefile。