-
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.
To use CppPandas, include the cppandas.h and cppandas.cpp files in your project and compile them with your C++ program.
#include "cppandas.h"You 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(5); // Show first 5 rowsstd::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.