Skip to content

Instantly share code, notes, and snippets.

View mickaellegal's full-sized avatar

Mickael Le Gal mickaellegal

View GitHub Profile
@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 / 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 / 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)) %>%