努力学习数据分析的周果昂 2020-03-22 19:18
浏览 394

DataFrame中怎么转换为values不带中括号的字典形式?利用Geo画城市地图遇到困难了

数据来源是天池新人赛的lisitngs(已经部分处理)


我打算用pyecharts画图


遇到的第一个问题是0.5和1.0的各种坑...


第二个问题就是总是产生


too many values to unpack (expected 2)这种错误报告


刚入门数据分析希望亲朋好友以及大佬爸爸们的猛烈鞭策...


代码如下:

pip install echarts-china-provinces-pypkg  -i https://mirrors.aliyun.com/pypi/simple# 中国省级地图
pip install echarts-china-cities-pypkg  -i https://mirrors.aliyun.com/pypi/simple# 中国市级地图
pip install echarts-china-misc-pypkg -i https://mirrors.aliyun.com/pypi/simple # 中国区域地图
#导入地图库
from pyecharts.charts import Geo
from pyecharts import options as opts
from pyecharts.globals import GeoType
data = pd.DataFrame(listings,columns=['id','price'])
data_pair = data.set_index('id').T.to_dict('list')
def test_geo():
    city = '北京'
    g = Geo()
    g.add_schema(maptype=city)
    # 定义坐标对应的名称,添加到坐标库中 add_coordinate(name, lng, lat)
    for i in range(len(data_pair)):
        g.add_coordinate(listings['name'][i],listings['longitude'][i],listings['latitude'][i])
    # 定义数据对
    g.add('', data_pair, type_=GeoType.EFFECT_SCATTER, symbol_size=5)    
    # 设置样式
    g.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    # 自定义分段 color 可以用取色器取色
    pieces = [
        {'max': 100, 'label': '100以下', 'color': '#50A3BA'},
        {'min': 101, 'max': 200, 'label': '100-200', 'color': '#3700A4'},
        {'min': 201, 'max': 300, 'label': '201-300', 'color': '#81AE9F'},
        {'min': 301, 'max': 400, 'label': '301-400', 'color': '#E2C568'},
        {'min': 401, 'max': 500, 'label': '401-500', 'color': '#FCF84D'},
        {'min': 501, 'max': 600, 'label': '501-600', 'color': '#DD0200'},
        {'min': 601, 'max': 700, 'label': '601-700', 'color': '#DD675E'},
        {'min': 701, 'label': '701以上', 'color': '#D94E5D'}  # 有下限无上限
    ]
    #  is_piecewise 是否自定义分段, 变为true 才能生效
    g.set_global_opts(
        visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=pieces),
        title_opts=opts.TitleOpts(title="{}-区域房屋以及价格分布".format(city)),
    )
    return g
g = test_geo()
g.render('test_render.html')

我怀疑是我的data_pair做的字典没做对
然后就开始报too many values to unpack (expected 2)

叩谢 帮到忙的请喝奶茶

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?