Skip to content

Instantly share code, notes, and snippets.

View mickaellegal's full-sized avatar

Mickael Le Gal mickaellegal

View GitHub Profile
@mickaellegal
mickaellegal / simulation_gganimate.R
Created March 9, 2019 15:22
Example of Simulation in R
library(tidyverse)
library(gganimate)
# Setup
options(gganimate.nframes = 200)
set.seed(2019)
simulation <- tibble(roll = 1:10000) %>%
mutate(result = sample(6, n(), replace = TRUE)) %>%
crossing(nrolls = seq(10, 10000, 10)) %>%
@mickaellegal
mickaellegal / convert_dates.py
Created August 7, 2014 09:10
Python: Cleaning dates
import pandas as pd
import numby as np
# import your csv file into a pandas dataframe
df = pd.DataFrame('YOUR_FILE.csv')
# convert the column with the date to a date format
date = pd.to_datetime(df.date_column)
# Change the format of the date
@mickaellegal
mickaellegal / df_unique_values.py
Last active August 29, 2015 14:02
Find unique string values in DataFrame that are not integer strings nor floats.
def get_unique_tracker_list(dataframe):
"""This function looks for unique string values in a dataframe."""
mylist = list(pd.Series(dataframe.values.ravel()).unique())
# Convert every element to a string.
templist = map(str, mylist)
# Return only the strings and deal with the floats.
mynewlist = [s for s in templist if s.replace(".", "", 1).isdigit() == False]
@mickaellegal
mickaellegal / ragged_csv.py
Created June 16, 2014 09:31
Python: Handle ragged csv files
import pandas as pd
import numpy as np
import csv
file = "YOUR_FILE_PATH"
# Read the csv with python
lines=list(csv.reader(open(file)))
# Get the name of the columns
@mickaellegal
mickaellegal / dayone_lcp
Last active February 6, 2017 05:23
Day One and Launch Center Pro Workflow
dayone://post?entry=My Daily Review
|Daily Review||
|:---|:---|
|Summary|[prompt: Today's one word summary]|
|Did I work?|[list: Did I work today?|Yes|No]|
|Did I relax?|[list: Did I relax today?|Yes|No]|
|Physical Exercise|[list: Did I workout today?|Yes|No]|
|Satisfaction|[list: Am I happy with what I did today?|Yes|No]|
|Goals|[list:Any progress toward my goals?|Yes|No]|
@mickaellegal
mickaellegal / book_reco.ipynb
Created February 2, 2014 08:55
iPython Notebook: Blog book recommendation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mickaellegal
mickaellegal / book_reco.py
Last active July 26, 2016 13:35
Python: Blog Pearson correlation coefficient for book reviews
# Importing the libraries
from scipy.stats.stats import pearsonr
import pandas as pd
import numpy as np
import json
data = pd.read_csv("../../Downloads/data_books.csv", sep = ",", header=None,
names=['Reviewer', 'Book', 'Rating'])
# Picking 2 books
@mickaellegal
mickaellegal / yhat.sh
Created January 30, 2014 16:49
Shell: yHat login
yh = Yhat("YHAT_USERNAME", "YHAT_APIKEY")
yh.deploy("NYTimesClassifier", myModel)
# Once everything is uploaded you should see the following message
uploading... done!
{u'modelname': u'NYTimesClassifier', u'status': u'success', u'version': 1}
@mickaellegal
mickaellegal / heroku.sh
Last active August 29, 2015 13:55
Shell: Heroku configuration yHat
Heroku create
git push heroku master
# Wait for the application to upload on heroku
heroku config:set YHAT_USERNAME=your_yhat_username
heroku config:set YHAT_APIKEY=your_yhat_api_key
@mickaellegal
mickaellegal / 50onRed_test_mlg
Created January 27, 2014 17:38
iPython Notebook: 50onRed test
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{