hupili / python-for-data-and-media-communication-gitbook

An open source book on Python tailed for communication students with zero background
118 stars 62 forks source link

The page for geopandas FAQ (and plotly choropleth example) #87

Closed hupili closed 6 years ago

hupili commented 6 years ago

https://github.com/hupili/python-for-data-and-media-communication-gitbook/blob/master/module-geopandas.md

FLYSTEPHEN commented 6 years ago

import numpy as np import pandas as pd

df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/laucnty16.csv') df_sample['State FIPS Code'] = df_sample['State FIPS Code'].apply(lambda x: str(x).zfill(2)) df_sample['County FIPS Code'] = df_sample['County FIPS Code'].apply(lambda x: str(x).zfill(3)) df_sample['FIPS'] = df_sample['State FIPS Code'] + df_sample['County FIPS Code']

colorscale = ["#f7fbff","#ebf3fb","#deebf7","#d2e3f3","#c6dbef","#b3d2e9","#9ecae1", "#85bcdb","#6baed6","#57a0ce","#4292c6","#3082be","#2171b5","#1361a9", "#08519c","#0b4083","#08306b"] endpts = list(np.linspace(1, 12, len(colorscale) - 1)) fips = df_sample['FIPS'].tolist() values = df_sample['Unemployment Rate (%)'].tolist()

fig = ff.create_choropleth( fips=fips, values=values, binning_endpoints=endpts, colorscale=colorscale, show_state_data=False, show_hover=True, centroid_marker={'opacity': 0}, asp=2.9, title='USA by Unemployment %', legend_title='% unemployed' ) py.iplot(fig, filename='choropleth_full_usa')


Get a U.S map
![newplot](https://user-images.githubusercontent.com/42834869/48928930-c8b28480-ef1e-11e8-9700-54f166a95784.png)
- If anyone find any new problem, please tell us and let's solve the problem together.
hupili commented 6 years ago

Good note. Edited into FAQ. @FLYSTEPHEN you may want to have a look. An FAQ structure is slight different. Error messages help people to search into that page.

Also added this case to week 13 mapping.

👍

FLYSTEPHEN commented 6 years ago

Got it! We need to extract essential information from the Error messages!

hupili commented 6 years ago

https://python-graph-gallery.com/292-choropleth-map-with-folium/

A project on the same topic but different library. FYR.