我试图在分区Map中显示捷克共和国各县的失业情况。
我有json坐标和失业数据保存在csv文件。但我得到这个错误:
Unicode编码错误:"charmap"编解码器无法解码位置211750中的字节0x88:字符Map到undefined。
这很奇怪,因为当我运行这段代码时(基本上是相同的代码,但数据不同):https://python-graph-gallery.com/292-choropleth-map-with-folium/一切正常。
我有一种感觉,这是不可能显示CZ县在分区Map或它?
您可以在此处找到我使用的文件:https://github.com/MichalLeh/CZ-map
import pandas as pd
import folium
# Load the shape of the zone
state_geo = 'J:/CZ-counties.json'
# Load the unemployment value of each state (county)
state_data = pd.read_csv('J:/CZ-unemploy.csv')
# Initialize the map:
m = folium.Map([15, 74], zoom_start=6)
# Add the color for the chloropleth:
choropleth = folium.Choropleth(
geo_data=state_geo,
name='choropleth',
data=state_data,
columns=['Name', 'Un'],
key_on='feature.id',
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Unemployment',
).add_to(m)
folium.LayerControl(collapsed=True).add_to(m)
# Save to html
m.save('map.html')
- 终端输出:**
Traceback (most recent call last):
File "J:\testCz", line 12, in <module>
choropleth = folium.Choropleth(
File "C:\Users\Michal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\folium\features.py", line 1247, in __init__
self.geojson = GeoJson(
File "C:\Users\Michal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\folium\features.py", line 453, in __init__
self.data = self.process_data(data)
File "C:\Users\Michal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\folium\features.py", line 491, in process_data
return json.loads(f.read())
File "C:\ProgramFiles\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\encodings\cp1250.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x88 in position 211750: character maps to undefined.
1条答案
按热度按时间0md85ypi1#
这是因为您的json文件是UTF-8。将UTF-8编码添加到Choropleth类参数中:
查看帖子:Python - UnicodeDecodeError:
您可以随时运行chardet来检查: