Data Visualization with Python and Javascript
1. Python vs JavaScript
Sample JS Code / Starting http via Python
Sample JavaScript Code let data = [3,7,2,8,1,11]; let sum = 0; data.forEach(function(d){ sum +=...
Python and Javascript caveats and considerations
Style Guidelines Python (Python Enhancement Proposal(PEP) 8) uses underscores in its variable na...
Importing Modules/Scripts
Python # Using alias for your import import pandas as pd # Importing a part of the library from c...
Simple Data Processing
Python # A student_data = [ {'name': 'Bob', 'id':0, 'scores':[68,75,56,81]}, ...
Data Types & Basic Functions
Python Python's data types types name primitive Integers primitive Float primitive Str...
Iteration
Python foo = {'a':3, 'b':2} for x in foo: print(x) a b for x in foo.items(): print(x) ('a'...
Conditionals: if elif else
Python if elif else if a > b: print('a is bigger') elif a < b: print('b is bigger') else: p...
File Input and Output
Python # Reading a file f = open("data.txt") # open file for reading for line in f: # iterate ov...
Classes and Prototypes
Python class Citizen(object): # Constructor def __init__(self, name, country): self.name...
ETC
Method Chaining Method chaining involves returning an object from its own method in order to call...
Python with Data
Reading and Writing Data with Python (CSV, JSON)
Example nobel_winners = [ {'category': 'Physics', 'name': 'Albert Einstein', 'nation...
Reading and Writing Data with Python (datetime)
JSON datetime Incompatibility class json.JSONDecoder(*, object_hook=None, parse_float=None, parse...
SQLAlchemy
SQLAlchemy SQLAlchemy Library SQLAlchemy Engine Configuration SQLAlchemy Declarative Mapping from...
Dataset
Dataset Dataset Documentation Feeding Data import dataset db = dataset.connect('sqlite:///nobel_...
MongoDB
Intro MongoDB uses binary JSON(BSON) as its data format. from pymongo import MongoClient # Creat...
Web Dev
Webdev 101(HTML)
Web Viz Components HTML skeleton Cascading Style Sheets (CSS): border widths, colors, font sizes...
Webdev 101(CSS)
Intro CSS is short for Cascading Style Sheets. CSS Order:\ !important after CSS property trump...
A Basic Page with Placeholders
HTML <!DOCTYPE html> <meta charset="utf-8"> <link rel="stylesheet" href="style.css" type="text/c...
Flex Box (CSS): Positioning and Sizing Containers
Flex Box .container { display: flex; width: 600px; height: 400px; border: 2px solid red; ...
Scalable Vector Graphics(SVG)
Basic SVG context SVG properties <!DOCTYPE html> <meta charset="utf-8"> <stlye> svg#chart { ...
Data Gathering/Wrangling
Getting Data: Requests library
Ways to get data off the web Get a raw data file in JSON or CSV over HTTP Use a dedicated API Sc...
Using Libraries to Access WEB APIs
gspread: Google Spreadsheets Python API OAuth gspread documentation import gspread gc = gspread....
Scraping Data with Python (Bautiful Soup, lxml)
Beautiful Soup Beautiful Soup Documentation Beautiful Soup is a HTML parser package for Python. f...
Srapy Part I : The Basics
How to Start $ conda install -c https://conda.anaconda.org/anaconda scrapy $ scrapy startproejct...
Scrapy Part II. Full Implementation
Full Implementation # nwinner_spider.py import scrapy import re BASE_URL = 'https://en.wikipedia...
Srapy Part III. Scrapy Pipelines
Basic # pipelines.py class DropNonPersons(object): def process_item(self, item, spider): if...
Cleaning and Exploring Data (numpy, pandas, matplotlib)
Numpy, Pandas
Numpy # Moving Average def moving_average(arr, n=3): """ returns n-moving average(default=3) ar...
Cleaning Data with pandas
Reading Data df = pd.read_json('data/nobel_winners_dirty.json') df.info() <class 'pandas.core.fra...
matplotlib Part I: Basics
Manipulating matplotlib import matplotlib as mpl mpl.rcParams['lines.linewidth'] = 3 mpl.rcParams...
matplotlib Part II: Bar Charts and Scatter Charts
Bar Charts labels = ['Physics', 'Chemistry', 'Literature', 'Peace'] foo_data = [3, 6, 10, 4] bar...
matplotlib Part III: seaborn
seaborn import numpy as np import pandas as pd import matplotlib as mpl import matplotlib.pyplot ...
numpy Cheat Sheet
random random.randn np.random.randn(d0, d1, ... , dn) randn returns a sample (or samples) from t...
pandas Cheat Sheet
pandas concat pandas.concat(objs, *, axis=0, join='outer', ignore_index=False, keys=None, levels=...
matplotlib Cheat Sheet
figure class matplotlib.figure.Figure(figsize=None, dpi=None, *, facecolor=None, ...