Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.