python - 叶图返回“TypeError:int64 类型的对象不是 JSON 可序列化的”
问题描述
在我下面的脚本中,Folium 图返回“TypeError:int64 类型的对象不是 JSON 可序列化的”。脚本的最后一行似乎有问题,因为当我注释它时,它会运行,但是当我取消注释它时,我得到 TypeError。我需要将文件绘制为 html 或 jpg。
import pandas as pd
import folium
from folium.plugins import HeatMap
from folium.plugins import MarkerCluster
for_map = pd.read_csv('datasets/sum_loads.csv')
max_amount = float(for_map['total_offs_sum'].max())
hmap = folium.Map(location=[51.5, -0.1], zoom_start=7)
hm_wide = HeatMap( list(zip(for_map.latitude.values, for_map.longitude.values, for_map.total_offs_sum.values)),
min_opacity=0.2,
max_val=max_amount,
radius=17, blur=12,
max_zoom=1,
)
hmap.add_child(hm_wide)
locations = list(zip(for_map.latitude, for_map.longitude))
cluster = MarkerCluster(locations)
hmap.add_child(cluster)
hm_wide.save('output_plot.html')
解决方案
根据 Christian 的建议,您的 for_map.total_offs_sum.values 很可能是整数。只需尝试将其转换为浮动即可。例如
hm_wide = HeatMap(list(zip(for_map.latitude.values, for_map.longitude.values,for_map.total_offs_sum.values.astype(float))),
min_opacity=0.2,
max_val=max_amount,
radius=17, blur=12,
max_zoom=1,
)
推荐阅读
- .net - .NET MVC 应用程序的 Office365 身份验证
- java - 将 Guava Sets 转换为 List 的最快方法
- angular - 如何以角度在数组中记录同一日期
- javascript - Hot Module Replacement 不会在更新 html 内容时重新加载,而是在 webpack 5 上的 css 和 js 上重新加载
- php - 在控制器中,我使用了输入标签,它将检查是否为“0”,然后未选中,否则检查。我有逃避问题
- python - 使用 np.where 函数 Numpy Python 通过数组添加
- sql - 根据 SQL 中查询的值添加指示“1”或“0”的列
- python - Python 从字符串中去除 \n 制表符
- css - 带有长箭头的引导工具提示,带有 css 或任何其他替代方法
- android - 在 Android 中以编程方式更改应用程序语言的问题