Link to census data tables:
https://api.census.gov/data/2015/acs/...
Tutorial code:
1 import plotly.offline as plt
2 from us.states import lookup
3 from census import Census
4 import pandas as pd
5 from os import getenv
6
7 ####### Grab census data ########
8 c = Census(getenv("CENSUS_API_KEY"))
9 data = c.acs5.state("B01002_001E", Census.ALL)
10 formatted_data = []
11 for entry in data:
12 state = lookup(entry["state"]).abbr
13 pop = entry.pop("B01002_001E")
14 formatted_data.append({"state": state, "POP": pop})
15 census_dataframe = pd.DataFrame(formatted_data)
16
17 ####### Build dictionaries and plot with plotly ########
18 data = [
19 dict(
20 type="choropleth",
21 locations=census_dataframe["state"],
22 z=census_dataframe["POP"].astype(float),
23 locationmode="USA-states",
24 )
25 ]
26
27 ####### Save the plot to an HTML file #######
28 fig = dict(data=data, layout={"geo":{"scope":"usa"}})
29 plt.plot(fig)
Soundtrack:
"A Vibe Nostalgic" by Mindseye
https://freemusicarchive.org/music/Mi...
Beyond cropping a snippet from the full song, no changes were made to this content.
US Map Video Clip:
https://pixabay.com/videos/kid-bike-r...
На этой странице сайта вы можете посмотреть видео онлайн Python US Census API Tutorial (Part IV) - Plot Median Age in Each State длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Roman's Coding Tutorials 10 Сентябрь 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 53 раз и оно понравилось 5 зрителям. Приятного просмотра!