A lightweight, high-performance C++ library for data manipulation and analysis, inspired by pandas.
- Fast and Efficient: Built with performance in mind using modern C++
- DataFrame Operations: Select, filter, head, and more
- Column-based Storage: Efficient columnar data structure
- Groupby Operations: Group data and perform aggregations (count, sum, mean)
- CSV Support: Read data from CSV files or strings
- Method Chaining: Fluent API for data pipelines
#include "DataFrame.h"
#include "CsvReader.h"
#include <iostream>
int main() {
// Read CSV data
std::string csv =
"price,volume,signal\n"
"101.5,2000,1\n"
"102.3,1800,0\n"
"99.8,2500,-1\n";
DataFrame df = readCSVString(csv);
// Select columns
auto view = df.select({ "price", "signal" });
// Filter data
auto filtered = view.filter("signal", [](double x) { return x != 0; });
// Group by and aggregate
auto result = df.groupby("signal").mean("price");
// Print results
std::cout << result << "\n";
return 0;
}Main data structure that holds columnar data with named columns.
Key Methods:
select(columns)- Select specific columnshead(n)- Get first n rowsgroupby(column)- Group by column valuesnumRows(),numCols()- Get dimensionsoperator[]- Access columns by name or index
Lightweight view into a DataFrame without copying data.
Key Methods:
select(columns)- Select columns from viewfilter(column, predicate)- Filter rows based on conditionhead(n)- Get first n rowsat(row, col)- Access specific cell
Result of groupby operation, enables aggregations.
Aggregation Methods:
count()- Count rows per groupsum(column)- Sum values per groupmean(column)- Calculate mean per group
Represents a single column of double values.
Methods:
sum(),mean(),min(),max(),median()- Aggregation functionsoperator[]- Access values by indexsize()- Get number of elements
- C++20 or later
- Visual Studio 2019/2022 (or any C++20 compatible compiler)
- Open
DataFrame.sln - Select your desired configuration (Debug/Release)
- Build the solution (F7)
mkdir build
cd build
cmake ..
cmake --build .Benchmark results on 1,000,000 rows:
| Operation | Time |
|---|---|
| select() | ~4.5 ms |
| select + head() | ~5.5 ms |
| select + filter() | ~53 ms |
| groupby + count() | ~179 ms |
| groupby + mean() | ~228 ms |
| Chained pipeline | ~207 ms |
DataFrame/
??? Column.h # Column implementation
??? DataFrame.h # DataFrame class
??? DataFrame.cpp # DataFrame implementation
??? DataFrameView.h # View implementation
??? DataFrameView.cpp # View implementation
??? GroupedDataFrame.h # Groupby operations
??? GroupedDataFrame.cpp # Groupby implementation
??? CsvReader.h # CSV parsing
??? CsvReader.cpp # CSV implementation
??? ColumnIO.h # Print operators
??? Benchmark.h # Benchmarking utilities
??? main.cpp # Example usage
// Read large dataset
DataFrame df = make_big_df(1'000'000);
// Chain operations
auto result = df
.select({ "price", "signal" })
.filter("signal", [](double x) { return x != 0; })
.groupby("signal")
.mean("price");
// Print formatted results
std::cout << result << "\n";// From string
std::string csv = "col1,col2\n1.0,2.0\n3.0,4.0\n";
DataFrame df = readCSVString(csv);
// From file
DataFrame df2 = readCSV("data.csv");The library includes formatted printing for all data structures:
std::cout << df << "\n"; // Print DataFrame
std::cout << view << "\n"; // Print DataFrameView
std::cout << df["price"] << "\n"; // Print ColumnOutput format:
price volume signal
------------ ------------ ------------
101.5 2000 1
102.3 1800 0
99.8 2500 -1
This project is open source. Feel free to use and modify as needed.
Contributions are welcome! Please feel free to submit issues or pull requests.
Created as a learning project to explore modern C++ and data structures.