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
for group_index, group in df.groupby(["road_number","cway"]): | |
blank_rows = group[group["cluster"].isna()] | |
filled_rows = group[group["cluster"].notna()] | |
for blank_row_index, blank_row in blank_rows.iterrows(): | |
# find distance by looing for minimum "signed overlap" | |
overlap_min = np.maximum(filled_rows["slk_from"], blank_row["slk_from"]) | |
overlap_max = np.minimum(filled_rows["slk_to"], blank_row["slk_to"]) |
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
def run_in_executor(f): | |
""" | |
This is a hack to turn a legacy blocking funciton into an async function. | |
Thanks to balki https://stackoverflow.com/a/53719009/1782370 | |
Example: | |
The following example shows how to use use a blocking | |
`azure.identity` credential type with `pandas.read_parquet()`. | |
Pandas normally requires that you use one of the limited |
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
def fuzzy_column_name_match(list1, list2): | |
from fuzzywuzzy import process | |
threshold = 60 | |
response = {} | |
for name_to_find in list1: | |
resp_match = process.extractOne(name_to_find ,list2) | |
if resp_match[1] > threshold: | |
response[name_to_find] = resp_match[0] | |
return response | |
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
def calculate_nickmapbi_offset(carriageway, xsp): | |
return { | |
"L":{ | |
f"L{num+1}": +3.5/2 - 3.5*num for num in range(0,7) | |
}, | |
"R":{ | |
f"R{num+1}": -3.5/2 + 3.5*num for num in range(0,7) | |
}, | |
"S":{ | |
f"L{num+1}": -3.5/2 - 3.5*num for num in range(0,7) |
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
#pip install pandas geopandas arcgis arcgis2geojson | |
import json | |
import geopandas as gpd | |
from geopandas import GeoDataFrame | |
from arcgis.features import FeatureLayer | |
from arcgis2geojson import arcgis2geojson | |
def get_arcgis_layer_as_geopandas(url:str) -> GeoDataFrame: | |
layer = FeatureLayer(url) |
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 threading | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
def serve_once(data:str, port=8000, host="127.0.0.1"): | |
""" | |
Serves the given data on the given port and host, then returns after | |
responding to one request. | |
This is a helpful way to send HTML to a browser being controled using Selenium. | |
""" |
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
function prompt { | |
$currentPath = (Get-Location).Path | |
$driveLetter = $currentPath.Substring(0,1) | |
$folderName = Split-Path $currentPath -Leaf | |
"$driveLetter:/.../$folderName> " | |
} |
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 pathlib import Path | |
import keyring | |
import pandas as pd | |
import os | |
import sys | |
# You need access to the compiled .NET AdomdClient .dll | |
# You can get it using nuget | |
# ```powershell | |
# nuget.exe install Microsoft.AnalysisServices.AdomdClient.retail.amd64 | |
# nuget.exe install Microsoft.AnalysisServices.Tabular |
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 | |
def split_dataframe_by_weighted_sequence( | |
df:pd.DataFrame, | |
split_column:str, | |
weight_column:str, | |
skew:float=0.5 | |
): | |
""" | |
Split a dataframe into two parts by a sequence of values and a sequence of weights. |
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
# pairwise coefficient of interpolation | |
Interp ← ÷:⊃(-≡⊢|≡/-)◫2 | |
MarchingSquares ← ( | |
: | |
⊃( | |
≡(◫2)Interp | |
| ◫2⍜⍉Interp | |
| ≡≡(°⋯♭)◫2_2> # types | |
| ≡°⍉⍉⊞⊟∩(⇡-1)⊃(⊢⇌|⊢)△ |