Skip to content

Instantly share code, notes, and snippets.

@cindygis
Created December 17, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cindygis/cc9d6c330e5dd76867c7 to your computer and use it in GitHub Desktop.
Save cindygis/cc9d6c330e5dd76867c7 to your computer and use it in GitHub Desktop.
Filters a pandas data frame using a mask
import pandas as pd
in_xls = r"C:\Some\Arb\Folder\test.xlsx"
columns = [0, 2, 3, 4, 6, 8]
# Use a function to define the mask
# to create a subset of the data frame
def mask(df, key, value):
return df[df[key] == value]
pd.DataFrame.mask = mask
# Out of the 101 rows, only 50 are stored in the data frame
df = pd.read_excel(in_xls,0, parse_cols=columns).mask('Create', 'Y')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment