问题描述
这是一个例子
import pandas as pd
import os
import numpy as np
import geopandas as gpd
import matplotlib.pyplot as plt
import seaborn as sns
import json
import requests
import folium as f
import geojson
import mapclassify as mc
url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'
county_data = f'{url}/us_county_data.csv'
county_geo = f'{url}/us_counties_20m_topo.json'
# read the data
df = pd.read_csv(county_data,na_values=[' '])
# define the quantiles,teh vector is then sored as quantiles.yb
quantiles = mc.Quantiles(df['Unemployed_2011'],k=5)
colorscale = branca.colormap.linear.YlOrRd_09.scale(0,50e3)
employed_series = df.set_index('FIPS_Code')['Employed_2011']
def style_function(feature):
employed = employed_series.get(int(feature['id'][-5:]),None)
return {
'fillOpacity': quantiles.yb,'weight': 0,'fillColor': '#black' if employed is None else colorscale(employed)
}
m = f.Map(
location=[48,-102],tiles='cartodbpositron',zoom_start=3
)
f.TopoJson(
json.loads(requests.get(county_geo).text),'objects.us_counties_20m',style_function=style_function
).add_to(m)
m
这使我出错;
TypeError: Object of type ndarray is not JSON serializable
基本上,我想基于具有权重的数组来更改多边形的不透明度,该权重是根据数据集中的变量之一计算得出的。我猜想lambda可以以某种方式使用,但是我的努力都不起作用。有人可以帮忙吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)