This file contains hidden or 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 datetime | |
| import pandas as pd | |
| import pytz | |
| import time | |
| # To switch logging on/off add config logic here to determine this variable: | |
| LOG_PERFORMANCE = True | |
| TIMEZONE = "US/Eastern" |
This file contains hidden or 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
| # Class: | |
| class PrintCheck: | |
| """Decorator to print a custom message when calling a function, followed by | |
| a check/tick mark on the same line when the computation finishes. If the | |
| function returns an integer it will be printed in parentheses with the check | |
| mark along with the `item_name` argument, pluralized if greater than 1.""" | |
| def __init__(self, msg: str = None, print_items: bool = True, | |
| item_name: str = "item"): | |
| """ |
This file contains hidden or 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 input_iterable_paginated(msg: str, iterable: object, page_length: int = 5, | |
| more: str = "m"): | |
| """List numbered items from any iterable to be chosen by user input.""" | |
| def get_input(valid: list): | |
| value = input().strip().lower() | |
| try: | |
| value = int(value) | |
| if value - 1 in range(len(valid)): | |
| return valid[value - 1] | |
| else: |
This file contains hidden or 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 | |
| from sklearn.preprocessing import PolynomialFeatures | |
| def apply_polynomials(df: pd.DataFrame, degree: int = 2, | |
| interaction_only: bool = False, | |
| include_bias: bool = False): | |
| """Apply scikit-learn's PolynomialFeatures class to a pandas DataFrame, | |
| keeping the original column labels and index, and extending the columns to | |
| include all new polynomial features. Generally speaking creates a lot of new |
OlderNewer