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
license: mit |
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
license: mit |
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
tumble_after( | |
broke( | |
fell_down( | |
fetch(went_up(jack_jill, "hill"), "water"), | |
jack), | |
"crown"), | |
"jill" | |
) |
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
( | |
jack_jill | |
.went_up("hill") | |
.fetch("water") | |
.fell_down("jack") | |
.broke("crown") | |
.tumble_after("jill") | |
) |
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
data = load_wine() | |
wine = pd.DataFrame(data.data, | |
columns=data.feature_names) | |
wine.head() |
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
( | |
wine.rename(columns={"color_intensity": "ci"}) | |
.assign(color_filter=lambda x: np.where((x.hue > 1) & (x.ci > 7), 1, 0)) | |
.query("alcohol > 14 and color_filter == 1") | |
.sort_values("alcohol", ascending=False) | |
.reset_index(drop=True) | |
.loc[:, ["alcohol", "ci", "hue"]] | |
) |
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 csnap(df, fn=lambda x: x.shape, msg=None): | |
""" Custom Help function to print things in method chaining. | |
Returns back the df to further use in chaining. | |
""" | |
if msg: | |
print(msg) | |
display(fn(df)) | |
return df |
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
( | |
wine.pipe(csnap) | |
.rename(columns={"color_intensity": "ci"}) | |
.assign(color_filter=lambda x: np.where((x.hue > 1) & (x.ci > 7), 1, 0)) | |
.pipe(csnap) | |
.query("alcohol > 14") | |
.pipe(csnap) | |
.sort_values("alcohol", ascending=False) | |
.reset_index(drop=True) | |
.loc[:, ["alcohol", "ci", "hue"]] |
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
data = load_iris() | |
iris = pd.DataFrame(data.data, columns=data.feature_names) | |
( | |
iris.pipe(csnap, lambda x: x.head(), msg="Before") | |
.pipe( | |
setcols, | |
fn=lambda x: x.columns.str.lower() | |
.str.replace(r"\(cm\)", "") | |
.str.strip() |
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 logging | |
import sys | |
logger = logging.getLogger() | |
fhandler = logging.FileHandler(filename="mylog.log", mode="a") | |
formatter = logging.Formatter( | |
"%(asctime)s - %(name)s - %(levelname)s - %(message)s" | |
) | |
fhandler.setFormatter(formatter) | |
logger.addHandler(fhandler) |
OlderNewer