Skip to content

Instantly share code, notes, and snippets.

View EdMan1022's full-sized avatar
💭
working

Edward Brennan EdMan1022

💭
working
  • Red Hat
  • Raleigh, NC
View GitHub Profile
@EdMan1022
EdMan1022 / scratch_9.py
Created August 11, 2017 20:06
sklearn pca example
from sklearn import decomposition
import numpy as np
pca = decomposition.PCA(n_components=2)
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
x = pca.fit_transform(X)
@EdMan1022
EdMan1022 / null_categorical_variables.py
Created September 1, 2017 21:24
Create a dataframe with null variable columns indicating indices with null values for each column
import pandas as pd
import numpy as np
df = pd.DataFrame(data=[[3., 1., np.NaN], [np.NaN, 3., 2.], [4., 1., 3.]], index=[0, 1, 2],
columns=['apple', 'carrot', 'pear'])
def null_only_categorical_func(data):
"""
Take a series, and return values of 1. where the series is null
@EdMan1022
EdMan1022 / df_to_txt.py
Created September 22, 2017 15:52
Pandas dataframe to txt file with comma delimiter test
import pandas as pd
# Pandas dataframe to txt file with comma delimiter test
df = pd.DataFrame(index = [0,1,2,3,4])
df.loc[:, 'a'] = 'a'
df.loc[:, 'b'] = 2
df.loc[:, 'c'] = ' '
df.loc[:, 'd'] = None
@EdMan1022
EdMan1022 / Flask-blueprint-with-imported-routes
Created November 7, 2017 18:02 — forked from Jaza/Flask-blueprint-with-imported-routes
Example of how to split a Flask blueprint into multiple files, with routes in each file, and of how to register all those routes.
*
@EdMan1022
EdMan1022 / scratch.jinja2
Created November 27, 2017 18:29
Ajax trouble
{% extends 'utilities/base.html' %}
{% block title %}{{ analysis_group.name }}{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-8">
<div class="card border-primary mb-3">
<div class="card-header">
<h3>{{ analysis_group.name }}</h3>
<h4>{{ analysis_group.description }}</h4>
</div>
from flask import Blueprint, request
from ..helper_functions import cluster_analysis_function
analytics = Blueprint('analytics', __name__, template_folder='templates')
@analytics.route('/api/analytics/cluster_analysis', methods=['GET'])
def cluster_analysis_view():
"""
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from voxco_survey_analysis.exceptions import InvalidUsage
from ..models import Analytic
def cluster_analysis_function(request):
"""
Perform a cluster analysis using the analysis group specified in the request
@EdMan1022
EdMan1022 / form.json
Created January 15, 2018 00:35
form json example
{
"specifications":
{
"age": [
{
"min_age": "20",
"max_age": "25",
"sample_size": "20"
},
{
@EdMan1022
EdMan1022 / stack_overflow_question_49700822.ipynb
Created April 6, 2018 22:34
Scrap for stack overflow answer
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@EdMan1022
EdMan1022 / rrule_intersection.py
Created July 6, 2018 04:11
Creates an interval of monthly dates, but replacing weekend dates with the nearest weekday date
import datetime
from dateutil import rrule as rr, relativedelta as rd
start_date = datetime.datetime(year=2017, month=1, day=1)
end_date = datetime.datetime(year=2018, month=1, day=1)
# Generate rule for valid dates under simple rule (Monthly from start until end)
valid_rule = rr.rrule(freq=rr.MONTHLY, dtstart=start_date, until=end_date)