Skip to content

Instantly share code, notes, and snippets.

@baskaufs
baskaufs / grades.csv
Created September 29, 2020 20:28
fake grades for R exercise
name tests participation paper
Able 99 pass 80
Baker 56 pass 65
Gammow 75 fail 95
Ephriam pass 75
Zulu 87 pass 90
Foxtrot 56 fail
Tanger 67 pass
@baskaufs
baskaufs / hw.R
Created September 25, 2020 19:01
stripped down hw example
# question 6
url3 <- "https://gist.githubusercontent.com/baskaufs/510972a23e3153edc133e33a2fcdf3d1/raw/ce8d6f160d5716b418a9874c22e614d95946a9be/wv_5_women_and_development.csv"
hw_table2 <- read.csv(url3,na.strings="..")
mentions_gender <- hw_table2$nondiscrimination_clause_mentions_gender_in_the_constitution[1:217]
women_20to24 <- hw_table2$percentage_of_women_ages_20.24_first.married_by_age_18[1:217]
plot(women_20to24 ~ mentions_gender)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dwc: <http://rs.tdwg.org/dwc/terms/>
PREFIX dwciri: <http://rs.tdwg.org/dwc/iri/>
PREFIX dsw: <http://purl.org/dsw/>
PREFIX tc: <http://rs.tdwg.org/ontology/voc/TaxonConcept#>
select distinct ?tree ?date ?lat ?long ?nameString where {
?tree dsw:hasOccurrence ?occurrence.
?tree dsw:hasIdentification ?identification.
@baskaufs
baskaufs / wv_5_women_and_development.csv
Created September 19, 2020 18:21
World Bank Women and Development data
country male_life_expectancy_at_birth_2017 female_life_expectancy_at_birth_2017 percentage_of_women_ages_20-24_first married_by_age_18 male_financial_account_ownership female_financial_account_ownership male_employment_percentage female_employment_percentage firms_with_female_participation_in_ownership female_share_of_employment_in_senior_and_middle_management women_in_parliaments_percentage_seats nondiscrimination_clause_mentions_gender_in_the_constitution
Afghanistan 62.7 65.7 34.8 22.5 7.2 13.3 4.3 2.2 4.3 28 no
Albania 76.6 80.1 11.8 42 38.1 41.5 44.3 12.5 29.3 30 yes
Algeria 75.3 77.7 2.5 56.3 29.3 68.2 73.7 .. .. 26 yes
American Samoa .. .. .. .. .. .. .. .. .. .. ..
Andorra .. .. .. .. .. .. .. .. .. 50 ..
Angola 57.7 63.3 30.3 .. .. 40.4 16.8 .. .. 30 yes
Antigua and Barbuda 75.6 77.9 .. .. .. .. .. .. .. 11 yes
Argentina 72.9 79.7 .. 46.5 50.8 71.9 78.6 57.8 32.6 39 ..
Armenia 71.1 78.2 5.3 55.8 40.9 57.9 59.8 25.3 .. 24 yes
@baskaufs
baskaufs / replace_missing.py
Created September 19, 2020 13:43
Replaces empty strings in a CSV with zeros
import csv
from statistics import mean
# read from a CSV file into a list of dictionaries
def read_dict(filename):
with open(filename, 'r', newline='', encoding='utf-8') as file_object:
dict_object = csv.DictReader(file_object)
array = []
for row in dict_object:
array.append(row)
first_name middle_name last_name age number more_numbers
Harry Truman NaN 0 3
Hyram Ullysses Grant -9999 5
Beyonce NA 39 2 NA
@baskaufs
baskaufs / peo
Created September 17, 2020 13:54
test import file
first_name,middle_name,last_name,age,number,more_numbers
Harry,,Truman,NaN,0,3
Hyram,Ullysses,Grant,-9999,,5
Beyonce,,NA,39,2,NA
@baskaufs
baskaufs / people.csv
Created September 16, 2020 23:41
test import file
first_name middle_name last_name age
Harry Truman NaN
Hyram Ullysses Grant -9999
Beyonce NA 39
@baskaufs
baskaufs / rdf_tabular_command.txt
Created August 23, 2020 02:03
command line to invoke RDF::Tabular to convert CSV to RDF/Turtle
rdf serialize --input-format tabular --output-format ttl --metadata csv-metadata.json
@baskaufs
baskaufs / construct-direct-prop-statements.sparql
Created August 8, 2020 22:24
Construct statements using direct properties from indirect p: and ps: properties
construct {?item ?directProp ?value.}
from <http://nursing1>
where {
?item ?p ?statement.
?statement ?ps ?value.
filter(substr(str(?ps),1,39)="http://www.wikidata.org/prop/statement/")
bind(substr(str(?ps),40) as ?id)
bind(substr(str(?p),30) as ?id)
bind(iri(concat("http://www.wikidata.org/prop/direct/", ?id)) as ?directProp)
}