Created
December 17, 2015 10:09
-
-
Save cindygis/cc9d6c330e5dd76867c7 to your computer and use it in GitHub Desktop.
Filters a pandas data frame using a mask
This file contains 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
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