Created
January 27, 2019 18:00
-
-
Save adiamaan92/ed8fd08aa5e827575c410b197825369e to your computer and use it in GitHub Desktop.
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
def cfilter(df, fn, axis="rows"): | |
""" Custom Filters based on a condition and returns the df. | |
function - a lambda function that returns a binary vector | |
thats similar in shape to the dataframe | |
axis = rows or columns to be filtered. | |
A single level indexing | |
""" | |
if axis == "rows": | |
return df[fn(df)] | |
elif axis == "columns": | |
return df.iloc[:, fn(df)] | |
( | |
iris.pipe( | |
setcols, | |
fn=lambda x: x.columns.str.lower() | |
.str.replace(r"\(cm\)", "") | |
.str.strip() | |
.str.replace(" ", "_"), | |
).pipe(cfilter, lambda x: x.columns.str.contains("sepal"), axis="columns") | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment