Skip to content

Instantly share code, notes, and snippets.

View vmuriart's full-sized avatar

Victor Uriarte vmuriart

View GitHub Profile
# List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
# Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
# Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(valuelist)]
@vmuriart
vmuriart / Main.sublime-menu
Created June 24, 2017 14:31 — forked from kaste/Main.sublime-menu
PyTest magic test runner
[
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
{
"caption": "Package Settings",
"mnemonic": "P",
@vmuriart
vmuriart / gist:38cdb30de6f1dd7410eb9518a7011d3e
Created June 20, 2017 15:16 — forked from asabaylus/gist:3071099
Github Markdown Heading Anchors

Anchors in Markdown

To create an anchor to a heading in github flavored markdown. Add - characters between each word in the heading and wrap the value in parens (#some-markdown-heading) so your link should look like so:

[create an anchor](#anchors-in-markdown)

@vmuriart
vmuriart / gist:2b49cad1a81c9449078652cce1790e76
Created May 26, 2017 03:46 — forked from twneale/gist:5245670
.pythonrc file that adds command history and tab completion to my python shell.
'''
Save this file and add the following line to your ~/.bashrc"
export PYTHONSTARTUP="$HOME/.pythonrc"
'''
import os
import readline
import rlcompleter
import atexit
@vmuriart
vmuriart / hdf_to_parquet.py
Created May 18, 2017 00:31 — forked from jiffyclub/hdf_to_parquet.py
Do the same thing in Spark and Pandas
"""
Convert Pandas DFs in an HDFStore to parquet files for better compatibility
with Spark.
Run from the command line with:
spark-submit --driver-memory 4g --master 'local[*]' hdf5_to_parquet.py
"""
import pandas as pd
@vmuriart
vmuriart / email_utils.py
Created April 30, 2017 18:16 — forked from turicas/email_utils.py
Send emails easily in Python (with attachments and multipart)
#!/usr/bin/env python
# coding: utf-8
# This little project is hosted at: <https://gist.github.com/1455741>
# Copyright 2011-2012 Álvaro Justen [alvarojusten at gmail dot com]
# License: GPL <http://www.gnu.org/copyleft/gpl.html>
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@vmuriart
vmuriart / example_image_utils.py
Created April 30, 2017 18:15 — forked from turicas/example_image_utils.py
Layer on top of Python Imaging Library (PIL) to write text in images easily
#!/usr/bin/env python
# coding: utf-8
# You need PIL <http://www.pythonware.com/products/pil/> to run this script
# Download unifont.ttf from <http://unifoundry.com/unifont.html> (or use
# any TTF you have)
# Copyright 2011 Álvaro Justen [alvarojusten at gmail dot com]
# License: GPL <http://www.gnu.org/copyleft/gpl.html>
from image_utils import ImageText
@vmuriart
vmuriart / recover_source_code.md
Created March 12, 2017 20:22 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@vmuriart
vmuriart / markdown-to-email
Created October 12, 2016 17:16 — forked from cleverdevil/markdown-to-email
markdown-to-email A simple script to send beautifully formatted emails that you write in Markdown. The email will have an HTML payload and a plain-text alternative, so you'll make everyone happy, including yourself.
#!/usr/bin/env python
'''
Send an multipart email with HTML and plain text alternatives. The message
should be constructed as a plain-text file of the following format:
From: Your Name <your@email.com>
To: Recipient One <recipient@to.com>
Subject: Your subject line
---
@vmuriart
vmuriart / sqlite2parquet.py
Created June 23, 2016 00:56 — forked from beauzeaux/sqlite2parquet.py
sqlite2parquet
import sqlite3
import os
import argparse
try:
import pyspark
import pyspark.sql
except ImportError:
import sys
import os