-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation
Shakibul Islam edited this page Mar 30, 2025
·
3 revisions
cppandas is a lightweight C++ library for handling tabular data, inspired by Python's pandas. It provides basic functionalities for loading, manipulating, and displaying data from CSV files.
If you prefer linking against the precompiled static library (libcppandas.a), follow these steps:
- Copy
cppandas.hto your project's include directory. - Copy
libcppandas.ato your project'slibdirectory. - Compile and link
example g++
g++ main.cpp -o main -Iinclude -Llib -lcppandasInclude cppandas.h and cppandas.cpp in your project:
#include "cppandas.h"Compile with:
g++ main.cpp cppandas.cpp -o mainYou can create a DataFrame manually using a map of column names to vectors of values.
std::map<std::string, std::vector<std::string>> data = {
{"Name", {"Alice", "Bob", "Charlie"}},
{"Age", {"25", "30", "35"}}
};
DataFrame df(data);
df.show_frame();DataFrame df;
df.read_csv("data.csv");
df.show_frame();df.head(); // default Show first 5 rows
df.head(10); // Show first 10 rows std::vector<std::string> ages = df["Age"];std::vector<std::vector<int>> matrix = df.to_vector<int>({"Age"});df.dropna(); // Remove rows with NaN values
df.fillna("0"); // Replace NaN values with "0"df.drop_col("Age");
df.drop_col({"Name", "Age"});- Default constructor.
- Constructs a DataFrame from a map of column names to vectors.
- Loads data from a CSV file.
- Displays the first
nrows.
- Returns the values of a column as a vector.
template<typename type> std::vector<std::vector<type>> to_vector(const std::vector<std::string>& cols)
- Converts selected columns to a 2D vector of the specified type.
- Prints the entire DataFrame.
- Removes rows containing NaN values.
- Replaces NaN values with a specified value.
- Removes a column by name.
- Removes multiple columns.
- Removes multiple columns using an initializer list.
cppandas is under the MIT License.