Skip to content

Instantly share code, notes, and snippets.

@you-zhou
you-zhou / ColourfulShell
Created March 23, 2018 01:00 — forked from ChrisMorrisOrg/ColourfulShell
Colourise and highlight text in your Python app when running through shell.
# Colourise - colours text in shell. Returns plain if colour doesn't exist.
def colourise(colour, text):
if colour == "black":
return "\033[1;30m" + str(text) + "\033[1;m"
if colour == "red":
return "\033[1;31m" + str(text) + "\033[1;m"
if colour == "green":
return "\033[1;32m" + str(text) + "\033[1;m"
if colour == "yellow":
return "\033[1;33m" + str(text) + "\033[1;m"
@you-zhou
you-zhou / useful_pandas_snippets.py
Created December 23, 2016 00:28 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# 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)]