我正在try 使用Plotly Express创建交互的人口普查数据集合,我使用censusdis包检索这些数据.这适用于我检索的两个变量,但不适用于第三个变量.以下是我演示该问题的代码:
import plotly.express as px
import censusdis.data as ced
from censusdis.datasets import ACS5
#variable = 'B19013_001E' # Works - Median Household Income
#variable = 'B25058_001E' # Works - Median Rent
variable = 'B01001_001E' # Does not work! Total Population
df = ced.download(
dataset=ACS5,
vintage=2022,
download_variables=['NAME', variable],
state='06',
county='075',
tract='*',
with_geometry=True)
df = df.set_index('NAME')
print(df.head())
fig = px.choropleth_mapbox(df,
geojson=df.geometry,
locations=df.index,
center={'lat': 37.74180915, 'lon': -122.38474831884692},
color=variable,
color_continuous_scale="Viridis",
mapbox_style="carto-positron",
opacity=0.5,
zoom=10)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
As I cycle through the variables, the resulting dataframes all appear similar, but the third one (B01001_001E
) generates a scale but not a map:
但是,GEOMETRY列看起来很好(实际上,它看起来与为其他变量返回的列相同).如果您能帮助我了解问题所在,并就如何解决问题提供建议,我将不胜感激.