Skip to content

Instantly share code, notes, and snippets.

View MartinMacharia's full-sized avatar

MartinMacharia

View GitHub Profile
@MartinMacharia
MartinMacharia / Oracle DB connection
Created November 18, 2019 06:09
Oracle DB connection
import cx_Oracle
import pandas as pd
import csv
ip = '**********'
port = ****
SID = '********'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
conn = cx_Oracle.connect('DB_USERNAME', 'DB_PASSWORD', dsn_tns)
c = conn.cursor()
@MartinMacharia
MartinMacharia / Edume ec2
Last active October 24, 2018 04:55
Edume Ec2
rom pandas.io.json import json_normalize
import json
import psycopg2
import pandas as pd
import requests
mm_get = requests.get('https://edume-api.herokuapp.com/stats/users',headers={"Authorization":'XXXXXXXXXXXXXXXXXXXXXXX'})mm_json=mm_get.json()
mm_json=mm_get.json()
data_1 = json_normalize(data = mm_json['data'],
record_path = ['courses','modules'],
record_prefix = 'courses.modules.',
@MartinMacharia
MartinMacharia / Edume PDT
Last active November 1, 2018 06:10
Edume PDT
view: edume_lessons {
derived_table: {
sql:
SELECT
courses_modules_completiondate,
courses_modules_id,
courses_modules_status,
courses_modules_title,
courses_id,
courses_title,
@MartinMacharia
MartinMacharia / Links stitch and chrome cast
Last active December 4, 2020 12:50
Google Cast Beta compatible with windows 10
@MartinMacharia
MartinMacharia / Mixed models
Last active September 20, 2017 06:36
LME4 Plantwise
---
output: word_document
---
# Plantwise data analysis
Data from PlantWise Kenya
## Comments on data
+ ClinicFormID doesn't show in my file when opened in Excel (no text, just empty cells) - could there be more missing fields?
@MartinMacharia
MartinMacharia / OFRA Spatial
Last active October 14, 2018 08:16
Loading raster, reprojection, extract covariates
#EDA OFRA Spatial
#load neccessary packages
library(maptools)
library(sp)
library(rgdal)
#Importing data;
#maptools: Tools for Reading and Handling Spatial Objects
#rgdal has issues with IDs when importing spatial objects
@MartinMacharia
MartinMacharia / Logistic Clean
Last active September 14, 2017 08:17
PlantWise adaptation logistic model
#lOGIT
setwd("c:/Users/machariam/Desktop/Logit")
list.files()
Dat=read.csv("Dat.csv")
names(Dat)
str(Dat)
hist(LandPercapita)
hist(MaizeLand)
hist(PPI)
#Box plot
#Colour
setwd("c:/Users/machariam/Desktop/Rwanda PW Impact report/Logit")
list.files()
Dat.Yield=read.csv("Dat.Yield.csv")
data=read.csv(file.choose(), header=T) # Import data called data
View(data)# View data
duplicated(data$Dup) #Check for duplicates on column Dup, not a very efficient way for large dataset
data$Dup[duplicated(data1$Dup)] #Show duplicate entries, somewhat difficult to read results
unique(data1[duplicated(data1$Dup),])#Better way of showing unique repeat entries
#PSM with different matching criteria, select best based on visual inspection of common support graphics
setwd("C:/users/machariam/Desktop/Rwanda PW Impact report")
getwd()
data=read.csv(file.choose(), header=T) # Import data called data
View(data)# View data
duplicated(data$Dup) #Check for duplicates on column Dup, not a very efficient way for large dataset
data$Dup[duplicated(data1$Dup)] #Show duplicate entries, don't like how results are displayed
unique(data1[duplicated(data1$Dup),])#Better way of showing unique repeat entries
#PSM
setwd("C:/users/machariam/Desktop/Rwanda PW Impact report")
getwd()
RwandaData=read.csv("CleanV4.csv")