Skip to content

Instantly share code, notes, and snippets.

View janbenetka's full-sized avatar

Jan Benetka janbenetka

  • Unacast
  • Pilsen, Czech Republic
View GitHub Profile
@janbenetka
janbenetka / colors_css_named.py
Created August 11, 2020 14:18
[Named colors] Default colors that have name in CSS. #python #color #css
colors = ['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure',
'beige', 'bisque', 'black', 'blanchedalmond', 'blue',
'blueviolet', 'brown', 'burlywood', 'cadetblue',
'chartreuse', 'chocolate', 'coral', 'cornflowerblue',
'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan',
'darkgoldenrod', 'darkgray', 'darkgrey', 'darkgreen',
'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange',
'darkorchid', 'darkred', 'darksalmon', 'darkseagreen',
'darkslateblue', 'darkslategray', 'darkslategrey',
'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue',
@janbenetka
janbenetka / pandas_isin_in_query.py
Created August 13, 2020 22:51
[Query with list comparison ala .isin()] #pandas #query
df.query('a in ["a", "b", "c"]')
id_list = ["a", "b", "c"]
df.query('a in @id_list')
@janbenetka
janbenetka / leading_zero.sql
Created August 23, 2020 17:31
[Add leading zeros in BigQuery] #leading_zero #bigquery
SUBSTR(FORMAT("00%d", state_fips ), -2) as state_fips,
SUBSTR(FORMAT("00000%d", fips ), -5) as fips,
@janbenetka
janbenetka / bq_array_to_string
Created September 23, 2020 14:58
BigQuery - unpacking array to string #bigquery
ARRAY_TO_STRING(homeContext.fipscode, ',')
@janbenetka
janbenetka / cartoframes_plot_polygons.py
Last active September 23, 2020 21:22
[Cartoframes plot ploygons with points] #carto #python
from cartoframes.viz import Map, Layer, basemaps
from cartoframes.viz import Layer, color_continuous_style, color_bins_style, basic_style, color_category_legend
_df = average_duration.copy()
metric = 'avg_duration_day'
origin_county = selected_area_geom.iloc[0]['county_name']
origin_state = selected_area_geom.iloc[0]['state_name']
@janbenetka
janbenetka / SettingwithCopyWarning.py
Last active October 14, 2020 17:43
[SettingwithCopyWarning] Pandas complaining SettingwithCopyWarning #python #pandas #errors
pd.set_option('mode.chained_assignment', None)
@janbenetka
janbenetka / bigquery_centroid.sql
Last active September 21, 2021 04:15
[Bigquery Centroid] #bigquery #geo #coordinates
ST_Y(ST_CENTROID(geog)) AS tract_lat,
ST_X(ST_CENTROID(geog)) AS tract_lon,
@janbenetka
janbenetka / airflow_slack_messaging.py
Created September 24, 2020 12:15
[Airflow > Slack message] Creation of DAG that notifies Slack channel #Airflow
slack_message = "Home & Work for bundleId {} is ready for shipping!".format("{{ ti.xcom_pull(task_ids='get_bundle_id') }}")
notify_slack = SimpleHttpOperator(
task_id="notify_slack",
endpoint=slack_webhook_url,
data=json.dumps(
{"attachments": [{"fallback": slack_message, "text": slack_message, "color": "good"}]}),
headers={"Content-Type": "application/json"},
depends_on_past=False,
response_check=lambda response: True if response.status_code == 200 else False,
http_conn_id="http_slack_hook"
@janbenetka
janbenetka / counties_fips_codes.md
Last active July 21, 2021 17:27
[Important Counties (FIPS codes)] FIPS codes #fips #geo #newyork #sf

San Francisco: 06075
Chicago (Cook county): 17031
Los Angeles County: 06037
Seattle (King County): 53033

New York:
New York County (Manhattan): 36061
Kings County (Brooklyn): 36047
Bronx County (The Bronx): 36005

@janbenetka
janbenetka / unacast_template.py
Created September 30, 2020 22:02
[Plotly Unacast Template] #plotly
!pip install plotly==4.8
# Quick way to install hind font
!npm install -g google-font-installer
!gfi install hind -v 300
import plotly.graph_objs as go
import plotly.io as pio
pd.options.plotting.backend = "plotly"