This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |