This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
#https://data.medicare.gov/Hospital-Compare/Readmissions-and-Deaths-Hospital/ynj2-r877 | |
inCSV = 'Readmissions_and_Deaths_-_Hospital.csv' | |
df = pd.read_csv(inCSV) | |
df.head(10) | |
df['latitude'] = (df.Location.str.split('(',1).str[1]).str.split(',',1).str[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE tablename ADD COLUMN new_col TEXT | |
UPDATE tablename SET new_col = to_char(old_col, '9,999,999') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Map Title</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
<link rel="shortcut icon" href="https://cartodb.com/assets/favicon.ico" /> | |
<style> | |
html, body, #map { | |
height: 100%; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df['col'] = ((((df['col']-df['col'].min()) / (df['col'].max() - df['col'].min()))*255).round()).astype(int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import json | |
import csv | |
import pandas as pd | |
import numpy as np | |
import decimal | |
D = decimal.Decimal | |
url = "https://www.wework.com/locations/all" | |
data = urllib2.urlopen(url).read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE table_name ADD COLUMN torque_class INTEGER; | |
UPDATE table_name SET torque_class = ROUND(((input_col - (SELECT MIN(input_col) FROM table_name)) / (( (SELECT MAX(input_col) FROM table_name) - (SELECT MIN(input_col) FROM table_name))) * 255)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def oneTest(): | |
return 'so' | |
def openJSON(inFile): | |
with open(inFile) as json_data: | |
data = json.load(json_data) | |
return data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
inFileName = 'data/cartojsontest1.carto.json' | |
ouFileName = 'data/cartojsontest1_change_zoom10.carto.json' | |
newMapName = 'THIS IS A TEST10' | |
zoomLevel = 12 | |
lat = '40.7127' | |
lng = '-75.0059' | |
oldDatasetName = 'infogroup_bus_2012_is_mcdonalds' | |
newDatasetName = 'infogroup_bus_2012_like_exxon' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cartodb import CartoDBAPIKey, CartoDBException, FileImport | |
from _secret_info import cartodb_domain, API_KEY | |
cl = CartoDBAPIKey(API_KEY, cartodb_domain) | |
fi = FileImport('nyctrees2015.csv', cl, create_vis='true', privacy='public') # Import csv file, set privacy as 'link' and create a default viz | |
fi.run() #https://github.com/CartoDB/cartodb-python | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from geopandas import GeoDataFrame | |
from shapely.geometry import Point | |
import fiona | |
df = pd.read_csv('data.csv') | |
geometry = [Point(xy) for xy in zip(df.x, df.y)] | |
crs = {'init': 'epsg:2263'} #http://www.spatialreference.org/ref/epsg/2263/ | |
geo_df = GeoDataFrame(df, crs=crs, geometry=geometry) |