Lightning fast OLAP-style point queries on Pandas DataFrames.
Project description
NanoCube
Lightning fast OLAP-style point queries on Pandas DataFrames.
NanoCube is a super minimalistic, in-memory OLAP cube implementation for lightning fast point queries upon Pandas DataFrames. It consists of only 27 lines of magical code that turns any DataFrame into a multi-dimensional OLAP cube. NanoCube shines when multiple point queries are needed on the same DataFrame, e.g. for financial data analysis, business intelligence or fast web services.
pip install nanocube
import pandas as pd
from nanocube import Cube
# create a DataFrame
df = pd.read_csv('sale_data.csv')
value = df.loc[(df['make'].isin(['Audi', 'BMW']) & (df['engine'] == 'hybrid')]['revenue'].sum().item()
# create a NanoCube and run sum aggregated point queries
cube = Cube(df)
for i in range(1000):
value = cube.get('revenue', make=['Audi', 'BMW'], engine='hybrid')
Lightning fast - really?
For aggregated point queries NanoCube is 100x to 1,000x times faster than Pandas. For the special purpose, NanoCube is also much faster than all other libraries, like Spark, Polars, Modin, Dask or Vaex. If such libraries are drop-in replacements with Pandas dataframe, you should be able to use them with NanoCube too.
How is this possible?
NanoCube uses a different approach. Roaring Bitmaps (https://roaringbitmap.org) are used to construct a multi-dimensional in-memory presentation of a DataFrame. For each unique value in a column, a bitmap is created that represents the rows in the DataFrame where this value occurs. The bitmaps are then combined to identify the rows relevant for a specific point query. Numpy is finally used for aggregation of results. NanoCube is a by-product of the CubedPandas project (https://github.com/Zeutschler/cubedpandas) and the result of the attempt to make OLAP-style queries on Pandas DataFrames as fast as possible in a minimalistic way.
What price do I need to pay?
First of all, NanoCube is free and MIT licensed. The first price you need to pay is the memory consumption, typically
up to 25% on top of the original DataFrame size. The second price is the time needed to initialize the cube, which is
mainly proportional to the number of unique values over all dimension columns in the DataFrame. Try the included samples
sample.py
or notebook to get a feeling for the performance of NanoCube.
(100x to 1000x times faster than Pandas). By default, all non-numeric columns will be used as dimensions and all numeric columns as measures. Roaring Bitmaps (https://roaringbitmap.org) are used to construct and query a multi-dimensional cube, Numpy is used for aggregations.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nanocube-0.1.1.tar.gz
.
File metadata
- Download URL: nanocube-0.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07ea70671912effe526a2c2a7040c2a04de95ba0d8a9ad6f22736de6c90cc0a5 |
|
MD5 | f86ad423b920e7e7a18814bbd576db4a |
|
BLAKE2b-256 | 0f64b6392c9a7d3471b68addf4d49f8827fc44eaaa13ffcb63e54302856ef012 |
File details
Details for the file nanocube-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: nanocube-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bef17676c7010a409f871e2a8c357b111551a38208733d5bdecc785cec7f5f9 |
|
MD5 | be8a01fa7a0f40005df49d06f2f87db0 |
|
BLAKE2b-256 | 3f4ff87df96d72843f36714584016ea44221747116682b4eba25a823b85f0364 |