Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tonmcg's full-sized avatar

Tony McGovern tonmcg

View GitHub Profile
@tonmcg
tonmcg / .block
Last active August 18, 2017 00:54
Scotch Rankings
border: no
license: gpl-3.0
@tonmcg
tonmcg / .block
Last active August 18, 2017 02:07
Bayesian Statistics
border: no
license: gpl-3.0
@tonmcg
tonmcg / .block
Last active December 11, 2017 16:48
Africa Choropleth Map
border: no
license: gpl-3.0
@tonmcg
tonmcg / Html.GetImages.pq
Last active January 4, 2018 22:29
M Language Helper Functions for HTML Parsing
let GetImages =
(url as text) =>
let
Protocol = Uri.Parts(url)[Scheme],
PathName = Uri.Parts(url)[Path],
Host = Uri.Parts(url)[Host],
Source = Text.From(Text.FromBinary(Web.Contents(url))),
GetTag = (Counter as number) =>
let
CurrentTag = Text.BetweenDelimiters(Text.BetweenDelimiters(Source, "<img", ">", Counter), "src=""", """"),
@tonmcg
tonmcg / tidytext_wordclouds.R
Created March 9, 2018 15:53 — forked from sfirke/tidytext_wordclouds.R
Make wordclouds from a text column in R
library(pacman)
p_load(tidytext, wordcloud, janeaustenr, dplyr)
data("stop_words")
ppdf <- data.frame(prideprejudice, stringsAsFactors = FALSE)
# create a word cloud
create_word_cloud <- function(dat, col_name, exclude = "", max.words = 50, colors = "#034772", ...){
col <- deparse(substitute(col_name))
dat %>%
@tonmcg
tonmcg / Table.Imputer.pq
Last active March 15, 2018 01:17
M Language Data Processing Functions
let Table.Imputer =
(table as table, columnName as text, strategy as text, optional axis as number) as table =>
let
InputTable = Table.AddIndexColumn(table, "index", 0, 1),
imputeList =
let
list = Table.Column(InputTable,columnName)
in
list,
imputeColumn =
@tonmcg
tonmcg / Table.GetDummies.pq
Last active March 18, 2018 12:05
M Language Data Processing Functions
let Table.GetDummies =
(sourceTable as table, columnName as text) as table =>
let
distinctTable =
let
source = Table.AddKey(Table.Distinct(Table.FromList(Table.Column(sourceTable, columnName), Splitter.SplitByNothing(), null, null, ExtraValues.Error)),{"Column1"},false),
addIndex = Table.AddIndexColumn(source, "index", 0, 1)
in
addIndex,
origTable =
@tonmcg
tonmcg / List.MinMaxScaler.pq
Last active March 20, 2018 12:52
M Language Data Processing Functions
let
List.MinMaxScaler = (initialList as list, optional outputRange as list) as list =>
let
featureRange = if outputRange is null then {0,1} else outputRange,
list = List.Buffer(initialList),
count = List.Count(list),
min = List.Min(list),
max = List.Max(list),
a = featureRange{0},
b = featureRange{1},
@tonmcg
tonmcg / List.RandomSelection.pq
Created March 20, 2018 06:45
M Language Data Processing Functions
let
List.RandomSelection = (sourceList as list) as text =>
let
Selection = sourceList{Number.RoundDown(Number.RandomBetween(0, List.Count(sourceList)))}
in
Selection,
DefineDocs = [
Documentation.Name = " List.RandomSelection",
Documentation.Description = " Randomly select a value from a list.",
@tonmcg
tonmcg / List.StandardScaler.pq
Created March 21, 2018 09:55
M Language Data Processing Functions
let
List.StandardScaler = (initialList as list) as list =>
let
list = List.Buffer(initialList),
count = List.Count(list),
sd = List.StandardDeviation(list),
m = List.Average(list),
Scaler = List.Generate(
()=> [n = 0],
each [n] < count,