Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
107 views
in Technique[技术] by (71.8m points)

python - I can't made maps in plotly

I'm currently creating my first data science project, I am using a Kaggle database called "COVID-19 World Vaccination Progress". And then I found myself in a problem. I'm trying to make a map on plotly and unfortunately I can't mount it, even after several attempts. Can someone help me?

world_vaccines = df.groupby(['country','vaccines'])[['people_vaccinated']].max().reset_index()
fig = px.choropleth(world_vaccines, locations="iso_alpha",
                color="lifeExp", # lifeExp is a column of gapminder
                hover_name="country",)
fig.show()
question from:https://stackoverflow.com/questions/65939346/i-cant-made-maps-in-plotly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think the root cause is the information you're trying to plot is not available in world_vaccines or the CSV (lifeExp and iso_alpha).

To remedy this I modified the groupby statement to include iso_code and then used that for the location input and people_vaccinated as the color input (although other stats are available).

Here's a working example:

import pandas as pd
import plotly.express as px

df = pd.read_csv('country_vaccinations.csv')

world_vaccines = df.groupby(['iso_code','vaccines'])[['people_vaccinated']].max().reset_index()
fig = px.choropleth(world_vaccines, locations="iso_code",
                color="people_vaccinated",
                hover_name="iso_code",)
fig.show()

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...