Skip to main content

Dataframe Memory Project

This tools aims to provide simple solution to save memory when using pandas' data frame. It is highly inspired by this kaggle post.

[!IMPORTANT] The very basic principle : for each column, this tool reduces int and float precision as much as possible so that

  1. Approximate method method='approx' : no duplicated values appear and the minimum and maximum can be re-encoded
  2. Exact method method='exact' : preserve absolute information by testing every value.

For object data type, the function is trying to create category.

Usage

from data_memory import reduce_memory
import numpy as np
import pandas as pd

df = pd.DataFrame(
    np.array(
        [[1, 2, "aaa"],
         [4, 5, "bbb"],
         [7, 8, "ccc"]] * 10000),
    columns=['a', 'b', 'c'])

reduce_memory(df, method="exact", verbose=True)

Yields the following decrease of memory

Memory usage input: 5.04 MB
Memory usage output: 0.09 MB
Decreased by: 98.28 % 
df.info()
 #   Column  Non-Null Count  Dtype   
---  ------  --------------  -----   
 0   a       30000 non-null  category
 1   b       30000 non-null  category
 2   c       30000 non-null  category

[!WARNING] In method='approx',

  1. This tool destroys information and should not be applied automatically to any dataframe but big ones
  2. It preserves relative but not absolute information

Metadata

Release files for dataframe-memory 2023.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dataframe-memory 2023.3.1
File Size Uploaded
dataframe_memory-2023.3.1.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dataframe-memory 2023.3.1
File Interpreter ABI Platform
dataframe_memory-2023.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.0 kB

Release files / dataframe_memory-2023.3.1.tar.gz

Download URL dataframe_memory-2023.3.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c0e5c25fb4fc4259447472d0f3d12661ec4004a0ed55d47ed6939aab3bcc3ac0
BLAKE2b-256 checksum
How to use checksums
ae5075f3dc4c64d9ddacfaa49dde202774e5e400d31d4e43e254ee361be752c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / dataframe_memory-2023.3.1-py3-none-any.whl

Download URL dataframe_memory-2023.3.1-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4c95977fc91b4fe7b73ee2fd2d8cf807e441dcad3ea949843f5bc796b2c34ce
BLAKE2b-256 checksum
How to use checksums
db382be0715587f232ee9b9806e6bbf074c99078393699fe59354ed60ff558a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

2023.3.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page