我正在使用这个链接中的代码.

https://devskrol.com/2021/12/27/choropleth-maps-using-python/

这是我的实际代码.

import plotly.express as px
 
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)
    
#import libraries
import pandas as pd
import plotly.express as px
 

fig = px.choropleth(df_mover, geojson=counties, 
                    locations='my_zip', 
                    locationmode="USA-states", 
                    color='switcher_flag',
                    range_color=(10000, 100000),
                    scope="usa"
                    )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

我只是try 从名为df_mover的数据帧中传递数据,该数据帧有两个字段:my_zip和Switcher_lag.当我在Jupyter笔记本上运行它时,它只是不停地运行;它永远不会停止.我只想绘制25条记录,所以这里的数据不会太多.最后,my_zip是数据类型Object.你知道这里可能出了什么问题吗?

推荐答案

由于您没有提供任何用户数据,所以我try 了您的代码,数据包括here的美国邮政编码.我认为问题在于您不需要指定位置模式.我指定CORPORY_FIPS作为 colored颜色 填充的位置和人口.

import plotly.express as px
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)
    
#import libraries
import pandas as pd
us_zip = pd.read_csv('data/uszips.csv', dtype={'county_fips': str}) 

fig = px.choropleth(us_zip,
                    geojson=counties, 
                    locations='county_fips', 
                    #locationmode="USA-states", 
                    color='population',
                    range_color=(1000, 10000),
                    scope="usa"
                    )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

enter image description here

Python相关问答推荐

机器人与Pyton Minecraft服务器状态不和

在使用Guouti包的Python中运行MPP模型时内存不足

如何使用上下文管理器创建类的实例?

在应用循环中间保存pandas DataFrame

如何使用symy打印方程?

Python json.转储包含一些UTF-8字符的二元组,要么失败,要么转换它们.我希望编码字符按原样保留

发生异常:TclMessage命令名称无效.!listbox"

Pandas DataFrame中行之间的差异

cv2.matchTemplate函数匹配失败

如何在turtle中不使用write()来绘制填充字母(例如OEG)

为什么np. exp(1000)给出溢出警告,而np. exp(—100000)没有给出下溢警告?

Python全局变量递归得到不同的结果

如何在BeautifulSoup/CSS Select 器中处理regex?

搜索按钮不工作,Python tkinter

Gekko中基于时间的间隔约束

提高算法效率的策略?

计算空值

将一个双框爆炸到另一个双框的范围内

以异步方式填充Pandas 数据帧

Beautifulsoup:遍历一个列表,从a到z,并解析数据,以便将其存储在pdf中.