我正在处理shp文件,在shp文件中保存geodataframe时遇到问题。在
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')
我在处理数据时没有问题,但当我尝试保存时
^{pr2}$并返回一个错误:
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'>
我解决了在开始时将编码改为拉丁语-1的问题
“bytes”和某些其他类型(如“list”)不支持shapefile的数据类型。以下是讨论此问题的github问题的link。在
我建议删除具有“bytes”类型对象的列,然后保存shapefile。在
如果该列非常重要,请将值更改为“string”类型,然后保存shapefile。在
相关问题 更多 >
编程相关推荐