Choropleth 地图中缺少状态?
Missing State in Choropleth Map?
我正在绘制所有 U.S 的等值线图。州使用国家的缩写代码而不是 FIPS 代码,它缺少密苏里州,但我将其包含在我的数据集中:https://raw.githubusercontent.com/naymalabonna/CSC474-Final-Project/main/Data/Jail%20Data/covid_prison_rates.csv
我用 2 个分区统计图试过这个,同样的问题是密苏里州丢失了。enter image description here
这是代码:
import pandas as pd
import plotly as py
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
import plotly.graph_objs as go
df = pd.read_csv('https://raw.githubusercontent.com/naymalabonna/CSC474-Final-Project/main/Data/Jail%20Data/covid_prison_rates.csv')
df.head()
data = dict(type ='choropleth',
colorscale = 'electric',
z = df['prisoner_cases_pct'],
locations = df['name'],
locationmode = 'USA-states',
text = df['name'],
marker = dict(line = dict(color = 'rgb(255, 255, 255)', width =1)),
colorbar = {'title': 'Prisoner Cases Rates'})
layout = dict(title = 'Prisoner COVID-19 Cases Rates',
geo = dict(scope ='usa'))
choromap = go.Figure(data = [data], layout = layout)
choromap.show()
密苏里州没有出现的原因是数据中的州缩写包含不必要的白色space;我运行通过你的快递数据确认了。
import pandas as pd
import plotly.express as px
#from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
import plotly.graph_objects as go
df = pd.read_csv('https://raw.githubusercontent.com/naymalabonna/CSC474-Final-Project/main/Data/Jail%20Data/covid_prison_rates.csv')
df.name.unique() #'MO ' is error
array(['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'Federal', 'FL',
'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD',
'MA', 'MI', 'MN', 'MS', 'MO ', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM',
'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'PR', 'SC', 'SD', 'TN',
'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY', 'National'],
dtype=object)
df.loc[25,'name'] = 'MO'
fig = px.choropleth(locations=df.name.unique().tolist(),
locationmode='USA-states',
color=df.name.unique().tolist(),
scope='usa')
fig.show()
我正在绘制所有 U.S 的等值线图。州使用国家的缩写代码而不是 FIPS 代码,它缺少密苏里州,但我将其包含在我的数据集中:https://raw.githubusercontent.com/naymalabonna/CSC474-Final-Project/main/Data/Jail%20Data/covid_prison_rates.csv
我用 2 个分区统计图试过这个,同样的问题是密苏里州丢失了。enter image description here
这是代码:
import pandas as pd
import plotly as py
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
import plotly.graph_objs as go
df = pd.read_csv('https://raw.githubusercontent.com/naymalabonna/CSC474-Final-Project/main/Data/Jail%20Data/covid_prison_rates.csv')
df.head()
data = dict(type ='choropleth',
colorscale = 'electric',
z = df['prisoner_cases_pct'],
locations = df['name'],
locationmode = 'USA-states',
text = df['name'],
marker = dict(line = dict(color = 'rgb(255, 255, 255)', width =1)),
colorbar = {'title': 'Prisoner Cases Rates'})
layout = dict(title = 'Prisoner COVID-19 Cases Rates',
geo = dict(scope ='usa'))
choromap = go.Figure(data = [data], layout = layout)
choromap.show()
密苏里州没有出现的原因是数据中的州缩写包含不必要的白色space;我运行通过你的快递数据确认了。
import pandas as pd
import plotly.express as px
#from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
import plotly.graph_objects as go
df = pd.read_csv('https://raw.githubusercontent.com/naymalabonna/CSC474-Final-Project/main/Data/Jail%20Data/covid_prison_rates.csv')
df.name.unique() #'MO ' is error
array(['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'Federal', 'FL',
'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD',
'MA', 'MI', 'MN', 'MS', 'MO ', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM',
'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'PR', 'SC', 'SD', 'TN',
'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY', 'National'],
dtype=object)
df.loc[25,'name'] = 'MO'
fig = px.choropleth(locations=df.name.unique().tolist(),
locationmode='USA-states',
color=df.name.unique().tolist(),
scope='usa')
fig.show()