Skip to content

Instantly share code, notes, and snippets.

View mohitbadwal's full-sized avatar

Mohit Badwal mohitbadwal

View GitHub Profile
@mohitbadwal
mohitbadwal / encode_decode_thread.py
Last active June 29, 2017 05:28
Encode and Decode categorical columns using MultiThreading approach for faster execution.
import threading
threads = []
class encodeClass(threading.Thread):
def __init__(self, threadID, dataset, columns):
threading.Thread.__init__(self)
self.threadID = threadID
self.dataset = dataset
@mohitbadwal
mohitbadwal / pandas_encode_decode_labels.py
Last active June 15, 2017 14:10
Functions to encode decode labels
def encode(dataset, list_columns_to_encode):
# using dictionary of dictionary to save the values which will be used later
dictionary_of_dictionary = {}
for column in list_columns_to_encode:
temp_dictionary = {}
temp = dataset[column].astype('category').value_counts().keys()
for j in range(0, len(temp)):
temp_dictionary[j] = temp[j]
dataset[column].replace(temp[j], j+1, inplace=True)
dictionary_of_dictionary[column] = temp_dictionary