Skip to content

Instantly share code, notes, and snippets.

@enamoria
enamoria / dataframe_reduce_memory.py
Created October 17, 2018 03:32
Reduce pandas dataframe memory usage
# 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))
# 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
@PJUllrich
PJUllrich / big-o.md
Last active June 28, 2024 20:25
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

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