$ docker
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 check_na(prev_dict): | |
| new_dict = {key:val for key, val in prev_dict.items() if val != 'NA'} | |
| return new_dict | |
| def parse_na(payload): | |
| fake_payload = {} | |
| for k, v in payload.items(): | |
| if isinstance(v,dict): | |
| fake_payload[k] = check_na(v) | |
| 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
| def extract_error_message(value, message = ''): | |
| for k, v in value.items(): | |
| if isinstance(v,dict): | |
| message += f'{k} -> ' | |
| message = extract_error_message(v, message) | |
| else: | |
| if isinstance(v,list): | |
| message += f'{k} : {v[0]}, ' | |
| else: | |
| message += f'{k} : {v}, ' |
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 string | |
| import re | |
| def clean_text(text): | |
| text = text.translate(string.punctuation) | |
| ## Convert words to lower case and split them | |
| text = text.lower().split() | |
| ## Remove stop words | |
| stops = set(stopwords.words("english")) |
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
| from __future__ import print_function | |
| import json | |
| def find_values(id, json_repr): | |
| results = [] | |
| def _decode_dict(a_dict): | |
| try: | |
| results.append(a_dict[id]) | |
| except KeyError: |
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 column_dropper(df, threshold): | |
| # Takes a dataframe and threshold for missing values. Returns a dataframe. | |
| total_records = df.count() | |
| for col in df.columns: | |
| # Calculate the percentage of missing values | |
| missing = df.where(df[col].isNull()).count() | |
| missing_percent = missing / total_records | |
| # Drop column if percent of missing is more than threshold | |
| if missing_percent > threshold: | |
| df = df.drop(col) |
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
| # pip install modin[all] | |
| # import modin.pandas as mpd | |
| import pandas as pd | |
| import math | |
| def handler(df, n_rows, file_name): | |
| if df.shape[0] >= n_rows: | |
| split_index_ = int(df.index[0]) + n_rows | |
| split_index = n_rows | |
| new_df = df.iloc[:split_index,:] |
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
| [program:celery] | |
| directory = <django_project_directory> example:[/home/ubuntu/prod/api] | |
| command = <virual_environment_directory/bin/celery> <command_to_be_executed> example: [/home/ubuntu/anaconda3/envs/api_env/bin/celery] [-A prodapi worker -l info --without-gossip --without-mingle --without-heartbeat -Ofair --pool=solo] | |
| stdout_logfile=/var/log/supervisor/celery.log | |
| stderr_logfile=/var/log/supervisor/celery.log | |
| user=<username> example: [ubuntu] |
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 tensorflow as tf | |
| from keras.backend.tensorflow_backend import set_session | |
| tf_config = tf.ConfigProto() | |
| tf_config.gpu_options.per_process_gpu_memory_fraction = 0.2 | |
| set_session(tf.Session(config=tf_config)) |