Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ecodiv
ecodiv / useful_pandas_snippets.py
Created April 11, 2017 18:23 — 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)]
# By Martin Jung (2015)
# http://conservationecology.wordpress.com/
# Takes a IUCN species id code as input, which
# can ether be queried from the api (http://api.iucnredlist.org/)
# or directly from the full database downloadable here:
# http://api.iucnredlist.org/index/all.csv
isForestSpecialist <- function (inputID)
{
print(paste("Now processing ID",inputID))