我想绘制船舶数据的地图。我正在使用以下代码:
Name div_rank ... bike run
0 Avila, Anthony 2470 138 ... 05:27:59 04:31:56
1 Lindgren, Mikael 1050 151 ... 05:17:51 03:49:20
swim 2472 non-null object
bike 2472 non-null object
run 2472 non-null object
Name div_rank ... bike run
count 2472 2472 ... 2472 2472
unique 2472 288 ... 2030 2051
top Jara, Vicente 986 -- ... --:--:-- --:--:--
freq 1 165 ... 122 165
但是当我运行代码时,它给了我以下错误:
UnicodeDecodeError:'utf-8'编解码器无法解码位置2的字节0xf1:下一行中的无效继续字节:
with open ('Data.txt', 'r',encoding = 'utf-8') as f:
d = json.load(f)
# create a dataFrame
df = pd.DataFrame(([dict(id=data['id'],
X = data['x'],
Y = data['y'],
)
for data in d['features']]))
lat = df['X'].values
lon = df['Y'].values
margin = 1 # create a margin for the maps
lat_min = min(lat) - margin
lat_max = max(lat) + margin
lon_min = min(lon) - margin
lon_max = max(lon) + margin
# create a map
m = Basemap(llcrnrlon= lon_min,
llcrnrlat= lat_min,
urcrnrlon = lon_max,
urcrnrlat= lat_max,
lat_0= (lat_max - lat_min) / 2,
lon_0= (lon_max - lon_min) / 2,
projection= 'merc',
resolution= 'h',
area_thresh= 10,
)
m.drawcoastlines() # draw a coastlines
m.drawcounties(zorder=20) # draw a countries map in graph
m.drawstates()
m.drawmapboundary(fill_color= '#46bcec')
m.fillcontinents(color= 'white', lake_color= '#85A6D9')
lons, lats = m(lon, lat)
m.scatter(lons, lats, marker = 'o', zorder= 5, s= 5, c= 'g', )
plt.title('Give a proper title')
plt.show()
我不知道如何解决它。