Skip to content

Instantly share code, notes, and snippets.

View robroc's full-sized avatar

Roberto Rocha robroc

View GitHub Profile
This file has been truncated, but you can view the full file.
{
"cells": [
{
"cell_type": "markdown",
"id": "theoretical-governor",
"metadata": {},
"source": [
"## Data prep"
]
},
@robroc
robroc / hdbscan_map_clusters.py
Last active April 29, 2024 11:35
An example of clustering points of a map with HDBSCAN and using weighted averages to find the optimal cluster center
# Thanks to Leland McInnes (@leland_mcinnes) for devising the weighting solution
import hdbscan
# https://hdbscan.readthedocs.io/en/latest/index.html
import numpy as np
"""Assume df is a pandas dataframe with latitude and longitude columns in WGS84"""
# Define a cluster selection epsilon to group points within this distance.
@robroc
robroc / fsa_fundraiser_parties_years.csv
Created September 30, 2019 19:41
Canada political finance data
fiscal_election_date FSA winning_party
2008 A0A Liberal Party of Canada
2008 A0B Liberal Party of Canada
2008 A0C Liberal Party of Canada
2008 A0E Liberal Party of Canada
2008 A0G Liberal Party of Canada
2008 A0H Liberal Party of Canada
2008 A0J Liberal Party of Canada
2008 A0K Liberal Party of Canada
2008 A0L Newfoundland and Labrador First Party
year name value lastValue
1990 BP CANADA 170
1990 EXXONMOBIL CANADA 105
1990 IMPERIAL OIL 87
1990 ENCANA 37
1990 HUSKY OIL 29
1990 PEMBINA 23
1990 HOME OIL COMPANY 22
1990 PETRO-CANADA 21
1990 CHEVRON CANADA 19
@robroc
robroc / montreal_yearly_film_permits.csv
Last active August 28, 2019 19:57
Montreal top 10 movie permits per year
year name value lastValue
1975 Imperial Oil Resources Limited 61
1975 BP Canada Energy Company 49
1975 Imperial Oil Resources 42
1975 Petro-Canada 30
1975 Gulf Canada Limited 21
1975 Pembina Resources Limited 12
1975 Chevron Canada Limited 11
1975 Dome Petroleum Ltd. 9
1975 ExxonMobil Canada Energy 9
@robroc
robroc / bilingual_mtl.csv
Last active November 21, 2015 16:51
Bilingual people in Montreal census tracts
CTUID CTNAME bilingual
4620001.00 0001.00 1015
4620002.00 0002.00 945
4620003.00 0003.00 2630
4620004.00 0004.00 1305
4620005.00 0005.00 1170
4620006.00 0006.00 1655
4620007.00 0007.00 2320
4620008.00 0008.00 1155
4620009.00 0009.00 1500
@robroc
robroc / index.html
Last active November 10, 2015 21:30
D3 map of census tracts on the Island of Montreal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Census tracts on Montreal island</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
@robroc
robroc / drugdata.csv
Last active November 11, 2015 17:15
Stacked horizontal bar chart with D3
drug negative neutral positive
Methamphetamine 36 6 11
MDMA 26 9 16
Cannabis 13 13 11
Peyote 11 15 10
PCP 15 12 8
Amphetamine 23 5 6
LSD 13 12 9
Ketamine 12 12 6
Mushrooms 8 12 9
@robroc
robroc / data.js
Created October 31, 2015 16:54
Bar charts with auto-generated filter buttons
var data =
[{"From":"WA", "Students":11906, "To":"WA"},
{"From":"WA", "Students":0, "To":"DE"},
{"From":"WA", "Students":60, "To":"DC"},
{"From":"WA", "Students":38, "To":"WI"},
{"From":"WA", "Students":4, "To":"WV"},
{"From":"WA", "Students":75, "To":"HI"},
{"From":"WA", "Students":76, "To":"FL"},
{"From":"WA", "Students":17, "To":"WY"},
{"From":"WA", "Students":21, "To":"NH"},
@robroc
robroc / election_results.tsv
Last active September 10, 2015 23:31
Canada House of Commons Election Results
year election_num election_abbr election_name party elected_members percentage_of_popular_vote number_of_valid_votes number_of_candidates voter_turnout Winner
1867 1 1st 1st General Election Conservative (1867-1942) 101 50% 73 Conservative (1867-1942)
1867 1 1st 1st General Election Liberal Party of Canada 80 49% 73 Conservative (1867-1942)
1867 1 1st 1st General Election Other 1% 73 Conservative (1867-1942)
1872 2 2nd 2nd General Election Conservative (1867-1942) 103 49.90% 70 Conservative (1867-1942)
1872 2 2nd 2nd General Election Liberal Party of Canada 97 49.10% 70 Conservative (1867-1942)
1872 2 2nd 2nd General Election Other 1% 70 Conservative (1867-1942)
1874 3 3rd 3rd General Election Liberal Party of Canada 133 53.80% 70 Liberal Party of Canada
1874 3 3rd 3rd General Election Conservative (1867-1942) 73 45.40% 70 Liberal Party of Canada
1874 3 3rd 3rd General Election Other 0.80% 70 Liberal Party of Canada