DataFrame Save

C++ DataFrame for statistical, Financial, and ML analysis -- in modern C++ using native types and contiguous memory storage

Project README

C++23 Build status <BR> GitHub Codacy Badge <BR> GitHub tag (latest by date) Conan Center VCPKG package

DataFrame Lion

<B>DataFrame documentation with code samples</B>

This is a C++ analytical library designed for data analysis similar to libraries in Python and R. For example, you would compare this to Pandas, R data.frame, or Polars <BR> You can slice the data in many different ways. You can join, merge, group-by the data. You can run various statistical, summarization, financial, and ML algorithms on the data. You can add your custom algorithms easily. You can multi-column sort, custom pick and delete the data. And more …<BR> DataFrame also includes a large collection of analytical algorithms in form of visitors. These are from basic stats such as <I>Mean</I>, <I>Std Deviation</I>, <I>Return</I>, … to more involved analysis such as <I>Affinity Propagation</I>, <I>Polynomial Fit</I>, <I>Fast Fourier transform of arbitrary length</I> … including a good collection of trading indicators. You can also easily add your own algorithms.<BR> DataFrame also employs extensive multithreading in almost all its API’s, for large datasets. That makes DataFrame especially suitable for analyzing large datasets.<BR> For basic operations to start you off, see Hello World. For a complete list of features with code samples, see documentation.

I have followed a few <B>principles in this library</B>:<BR>

  1. Support any type either built-in or user defined without needing new code
  2. Never chase pointers ala linked lists, std::any, pointer to base, ...
  3. Have all column data in contiguous memory space
  4. Never use more space than you need ala unions, std::variant, ...
  5. Avoid copying data as much as possible
  6. Use multi-threading but only when it makes sense
  7. Do not attempt to protect the user against garbage in, garbage out

Performance

You have probably heard of Polars DataFrame. It is implemented in Rust and ported with zero-overhead to Python (as long as you don’t have a loop). I have been asked by many people to write a comparison for <B>DataFrame vs. Polars</B>. So, I finally found some time to learn a bit about Polars and write a very simple benchmark.<BR> I wrote the following identical programs for both Polars and C++ DataFrame. I used Polars version 0.19.14. And I used C++20 clang compiler with -O3 option. I ran both on my, somewhat outdated, MacBook Pro.<BR> In both cases, I created a dataframe with 3 random columns. The C++ DataFrame also required an additional index column of the same size. Polars doesn’t believe in index columns (that has its own pros and cons. I am not going through it here). Each program has three identical parts. First it generates and populates 3 columns with 300m random numbers each (in case of C++ DataFrame, it must also generate a sequential index column of the same size). That is the part I am not interested in. In the second part, it calculates the mean of the first column, the variance of the second column, and the Pearson correlation of the second and third columns. In the third part, it does a select (or filter as Polars calls it) on one of the columns.

Results:<BR> The maximum dataset I could load into Polars was 300m rows per column. Any bigger dataset blew up the memory and caused OS to kill it. I ran C++ DataFrame with 10b rows per column and I am sure it would have run with bigger datasets too. So, I was forced to run both with 300m rows to compare. I ran each test 4 times and took the best time. Polars numbers varied a lot from one run to another, especially calculation and selection times. C++ DataFrame numbers were significantly more consistent.

C++ DataFrame:
    Data generation/load time:  26.945900 secs
    Calculation time:            1.260150 secs
    Selection time:              0.742493 secs
    Overall time:               28.948600 secs

Polars:
    Data generation/load time:  28.468640 secs
    Calculation time:            4.876561 secs
    Selection time:              3.876561 secs
    Overall time:               36.876345 secs

Pandas, for comparison:
    Data generation/load time:  36.678976 secs
    Calculation time:           40.326350 secs
    Selection time:              8.326350 secs
    Overall time:               85.845114 secs

C++ DataFrame source file <BR> Polars source file <BR> Pandas source file


Please consider sponsoring DataFrame, especially if you are using it in production capacity. It is the strongest form of appreciation


Installing using CMake

mkdir [Debug|Release]
cd [Debug|Release]

cmake -DCMAKE_BUILD_TYPE=Release -DHMDF_BENCHMARKS=1 -DHMDF_EXAMPLES=1 -DHMDF_TESTING=1 ..
cmake -DCMAKE_BUILD_TYPE=Debug -DHMDF_SANITY_EXCEPTIONS=1 -DHMDF_BENCHMARKS=1 -DHMDF_EXAMPLES=1 -DHMDF_TESTING=1 ..

make
make install

cd [Debug|Release]
make uninstall

Package managers

DataFrame is available on Conan platform. See the Conan docs for more information.<BR> DataFrame is also available on Microsoft VCPKG platform. See VCPKG docs for more information<BR>

Open Source Agenda is not affiliated with "DataFrame" Project. README Source: hosseinmoein/DataFrame