Skip to content

Instantly share code, notes, and snippets.

View dengjonathan's full-sized avatar

Jon Deng dengjonathan

View GitHub Profile
import numpy, sklearn
import pandas as pd
import os
# os.chdir('./Ranger Data/data')
def csv2dataframe(fileobj):
"""Returns csv file as a pandas dataframe"""
with open(fileobj, 'r') as f:
return pd.read_csv(f, header=0)
import numpy as np
import sklearn
import pandas as pd
def csv2dataframe(fileobj):
"""Returns csv file as a pandas dataframe"""
with open(fileobj, 'r') as f:
return pd.read_csv(f, header=0)
# read all csv files to DataFrame objects and append to list then concatenate all dfs in list into one 'super_df'
df_list = [csv2dataframe(file) for file in os.listdir(os.getcwd()) if file.endswith('.csv')]
ranger_classes = [1, 3, 4, 5, 6, 7, 8, 9, 10, 11]
super_df = pd.concat(df_list)
def useless_columns(df):
"""Returns list of columns with less than 30 not null values"""
columns = []
for col in df.columns:
# isnull returns a list-like object with True is an element in the column is NaN and False if element has value
null_list = pd.isnull(df[col])
real_values = len([i for i in null_list if i != True])
if real_values < 30:
columns.append(col)
return columns
function flatten(array) {
var output = [];
// iterate through all items in argument array
for (var j = 0; j < array.length; j++) {
var value = array[j];
// base case: value is not an array, so just push to output
if (!Array.isArray(value)) {
output.push(value);
} else {
// recursive case: if value is an array, flatten it to a 1D array.
@dengjonathan
dengjonathan / flattenReduce.js
Created August 9, 2016 01:46
flatten using reduce
function each(collection, callback) {
if (Array.isArray(collection)) {
for (var i = 0; i < collection.length; i++) {
callback(collection[i]);
}
} else {
for (var j in collection) {
callback(collection[j]);
}
}
@dengjonathan
dengjonathan / gulpfile.js
Created August 21, 2016 17:30
Front-End Development Gulpfile
var gulp = require('gulp');
var browserSync = require('browser-sync')
.create();
//var sass = require('gulp-sass');
// Static Server + watching scss/html files
gulp.task('serve', function () {
browserSync.init({
server: "./"
// implementation of quicksort
var quickSort = function (arr) {
if (arr.length === 0) {
return [];
}
var left = [];
var right = [];
var pivot = arr[arr.length - 1]; // use right most value as pivot
var quickSort = function (arr) {
if (arr.length === 0) {
return [];
}
var left = [];
var right = [];
var pivot = arr[arr.length - 1]; // use right most value as pivot
_.each(arr.slice(0, arr.length - 1), function (each) {
@dengjonathan
dengjonathan / asyncIO.js
Last active August 28, 2016 20:21
Node asyn I/O with callback after I/O returns
var http = require('http');
var bl = require('bl');
// file path is from enviroment variable passed in through CLI
var url = process.argv[2];
var consolidated = '';
var callback = function(data) {
consolidated += data;