Skip to content

Instantly share code, notes, and snippets.

You have a CSV file called `locations.csv` with columns: name, longitude, latitude, type (including 'Customer' rows), DCs, and plants.
I want you to:
1. Filter the data to only include rows where `type == 'Customer'`.
2. Generate synthetic one-period demand for these customers:
- Normal scenario: Draw from a normal distribution (mean=100, std=20), clip negatives at 0.
Generate a Python Script for [Project Objective] Visualization with [Visualization Tools] in a Jupyter Notebook
Body:
Objective:
Clearly describe the purpose of the project, the type of data involved, and the key insights or lessons you aim to convey through visualization. Mention whether you have an existing dataset or need to generate synthetic data.
Example:
Create a Python script to visualize supply chain network scenarios using Folium maps. The visualization should compare an optimal distribution strategy (multiple Distribution Centers) versus a suboptimal one (single Distribution Center) to highlight the impact on costs and delivery times. If no data file is provided, generate synthetic data for Distribution Centers (DCs) and Customers.
Write a Python script to generate synthetic supply chain data with the following rules:
Here is the detailed description based on the supply chain network:
Distribution Centers (DCs)
Washington, DC:
Located in the northeastern United States near major population centers.
Likely serves as a key hub for East Coast distribution.
Dallas, TX:
Positioned centrally in the southern United States.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from ortools.constraint_solver import pywrapcp
from ortools.constraint_solver import routing_enums_pb2
from scipy.spatial.distance import cdist
import matplotlib.cm as cm
# Set random seed for reproducibility
np.random.seed(42)
@FrankRuns
FrankRuns / analyze-ontime-three-models.py
Created April 28, 2024 15:19
Supporting analysis for How supply chain leaders improve on-time delivery with multiple models
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import dowhy
from dowhy import CausalModel
import networkx as nx
import math
import sklearn
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
@FrankRuns
FrankRuns / white-noise.R
Created January 23, 2024 11:20
Calculations supporting substack post called Analytics, now what?
# Replicate Bob's results from this LinkedIn post:
# https://www.linkedin.com/posts/bob-wilson-77a22ab_people-sometimes-say-ab-testing-requires-activity-7152792859878871040-X1Sr?utm_source=share&utm_medium=member_desktop
### Implement Fisher's Exact Test
# Create the contingency table
contingency_table <- matrix(c(0, 4, 7, 3), nrow = 2)
dimnames(contingency_table) <- list(c("Control", "Treatment"),
@FrankRuns
FrankRuns / data-analyst-mistakes.R
Created January 10, 2024 19:47
Script to simulate tv holiday episode data for data analysts make mistakes article
# Load Required Libraries
if (!require("MASS")) install.packages("MASS")
library(MASS)
# Define TV Shows
# A vector of TV show titles
tv_shows <- c(
"Breaking Bad", "Game of Thrones", "The Wire",
"Stranger Things", "The Crown", "Mad Men",
"The Sopranos", "Friends", "The Office",
@FrankRuns
FrankRuns / tidytuesday-drwho.R
Created November 28, 2023 11:59
Quick inspection and vis of Dr. Who dataset for TidyTuesday 2023-11-28
# load packages
library(tidyverse)
library(tidytuesdayR) # Used for loading datasets from the TidyTuesday project
# load datasets
tuesdata <- tidytuesdayR::tt_load('2023-11-28')
drwho_episodes <- tuesdata$drwho_episodes
drwho_directors <- tuesdata$drwho_directors
drwho_writers <- tuesdata$drwho_writers
@FrankRuns
FrankRuns / selection-bias-visual.r
Last active June 12, 2022 10:56
Very quick ggplot2 scatterplot visualization for selection bias article.
# purpose: visualize linear trend for all data and subset of data
# libraries
library(dplyr)
library(ggplot2)
# read data
d <- read.csv("mycsvfile.csv")
# quickl look
# purpose: helper script to determine my max heart rate
# load libraries
library(dplyr)
library(rethinking)
#### Read and Filter Data ----
# grab data