Map [1]
Operation | Time Complexity |
---|---|
Access | O(log n) |
Search | O(log n) |
Insertion | O(n) for <= 32 elements, O(log n) for > 32 elements [2] |
Deletion | O(n) for <= 32 elements, O(log n) for > 32 elements |
# given a dataframe | |
def reduce_precision(df): | |
import numpy as np | |
""" | |
usage: give a dataframe, this fuction returns an optimized dataframe | |
df = reduce_precision(df) | |
reference: https://gist.github.com/enamoria/fa9baa906f23d1636c002e7186516a7b |
# This function is used to reduce memory of a pandas dataframe | |
# The idea is cast the numeric type to another more memory-effective type | |
# For ex: Features "age" should only need type='np.int8' | |
# Source: https://www.kaggle.com/gemartin/load-data-reduce-memory-usage | |
def reduce_mem_usage(df): | |
""" iterate through all the columns of a dataframe and modify the data type | |
to reduce memory usage. | |
""" | |
start_mem = df.memory_usage().sum() / 1024**2 | |
print('Memory usage of dataframe is {:.2f} MB'.format(start_mem)) |