Data Scientist @ Propel Labs

Weekend Reviews

Last updated: July 4th, 20202020-07-04Project preview
In [1]:
import pandas as pd
import numpy as np
In [2]:
!pip install altair vega_datasets
Collecting altair
  Downloading altair-4.1.0-py3-none-any.whl (727 kB)
     |████████████████████████████████| 727 kB 13.3 MB/s eta 0:00:01
Collecting vega_datasets
  Downloading vega_datasets-0.8.0-py2.py3-none-any.whl (210 kB)
     |████████████████████████████████| 210 kB 48.8 MB/s eta 0:00:01
Requirement already satisfied: jsonschema in /usr/local/lib/python3.8/site-packages (from altair) (3.2.0)
Collecting toolz
  Downloading toolz-0.10.0.tar.gz (49 kB)
     |████████████████████████████████| 49 kB 10.8 MB/s eta 0:00:01
Requirement already satisfied: pandas>=0.18 in /usr/local/lib/python3.8/site-packages (from altair) (1.0.1)
Requirement already satisfied: entrypoints in /usr/local/lib/python3.8/site-packages (from altair) (0.3)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.8/site-packages (from altair) (2.11.1)
Requirement already satisfied: numpy in /usr/local/lib/python3.8/site-packages (from altair) (1.18.1)
Requirement already satisfied: six>=1.11.0 in /usr/local/lib/python3.8/site-packages (from jsonschema->altair) (1.14.0)
Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.8/site-packages (from jsonschema->altair) (19.3.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.8/site-packages (from jsonschema->altair) (45.2.0)
Requirement already satisfied: pyrsistent>=0.14.0 in /usr/local/lib/python3.8/site-packages (from jsonschema->altair) (0.15.7)
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.8/site-packages (from pandas>=0.18->altair) (2019.3)
Requirement already satisfied: python-dateutil>=2.6.1 in /usr/local/lib/python3.8/site-packages (from pandas>=0.18->altair) (2.8.1)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.8/site-packages (from jinja2->altair) (1.1.1)
Building wheels for collected packages: toolz
  Building wheel for toolz (setup.py) ... done
  Created wheel for toolz: filename=toolz-0.10.0-py3-none-any.whl size=55575 sha256=6e4cefd341188992984dab9d43cf5b0dd0b68369926566723e497ff9ca324e48
  Stored in directory: /root/.cache/pip/wheels/a5/2b/b5/05758d5828d65f2adef8fbb5d5484e4adb946ae1827a973a01
Successfully built toolz
Installing collected packages: toolz, altair, vega-datasets
Successfully installed altair-4.1.0 toolz-0.10.0 vega-datasets-0.8.0
WARNING: You are using pip version 20.0.2; however, version 20.1.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
In [3]:
import altair as alt

# load a simple dataset as a pandas DataFrame
from vega_datasets import data
cars = data.cars()

alt.Chart(cars).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
)
Out[3]:
In [4]:
import altair as alt
from vega_datasets import data

counties = alt.topo_feature(data.us_10m.url, 'counties')
source = data.unemployment.url

alt.Chart(counties).mark_geoshape().encode(
    color='rate:Q'
).transform_lookup(
    lookup='id',
    from_=alt.LookupData(source, 'id', ['rate'])
).project(
    type='albersUsa'
).properties(
    width=500,
    height=300
)
Out[4]:
In [13]:
india_districts_url = 'https://raw.githubusercontent.com/deldersveld/topojson/master/countries/india/india-districts.json'

districts = alt.topo_feature(india_districts_url, 'IND_adm2')

alt.Chart(districts).mark_geoshape(
    fill='lightgray',
    stroke='white'
).properties(
    width=800,
    height=600
)
Out[13]:
In [11]:
# US states background
background = alt.Chart(districts).mark_geoshape(
    fill='lightgray',
    stroke='white'
).properties(
    width=500,
    height=300
)
In [12]:
background
Out[12]:
In [ ]:
 
Notebooks AI
Notebooks AI Profile20060