|
Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
|
Simple column-oriented data structure with basic analysis utilities. More...
#include <DataFrame.h>
Public Member Functions | |
| DataFrame () | |
| Default constructor. | |
| template<typename T > | |
| void | addColumn (const std::string &colName) |
| Adds a new empty column of type T. | |
| template<typename T > | |
| void | addValueToColumn (const std::string &colName, const T &value) |
| Appends a value to an existing column. | |
| template<typename T > | |
| T | iat (size_t row, const std::string &colName) const |
| Positional access to a cell (row index, column name). | |
| template<typename T > | |
| T | at (const std::string &idxValue, const std::string &colName) const |
| Label-based access to a cell (index label, column name). | |
| template<typename T > | |
| Series< T > & | operator[] (const std::string &colName) |
| Accessor for a column as a modifiable Series<T>. | |
| void | print () const |
| Prints the DataFrame to std::cout in a tabular format. | |
| const std::vector< std::string > & | getColumnNames () const |
| Returns the list of column names. | |
| size_t | getRowCount () const |
| Returns the number of rows in the DataFrame. | |
| DataFrame | head (size_t n=5) const |
| Returns a new DataFrame with the first n rows. | |
| DataFrame | tail (size_t n=5) const |
| Returns a new DataFrame with the last n rows. | |
| template<typename T > | |
| void | describeColumn (const std::string &colName) const |
| Prints a statistical summary for a single numeric column. | |
| void | describe () const |
| Prints a summary for all numeric columns. | |
| template<typename T > | |
| Series< T > | getColumn (const std::string &colName) const |
| Returns a copy of a column as a Series<T>. | |
| void | setIndex (const std::vector< std::string > &newIndex) |
| Sets the index labels for all rows. | |
| const std::vector< std::string > & | getIndex () const |
| Returns the current index labels. | |
| void | to_csv (const std::string &filename) |
| Serializes the DataFrame to a CSV file. | |
| void | _set_csv_options (const CSVOptions &options) |
| Internal helper to set CSV options from an external source. | |
Public Attributes | |
| std::vector< std::string > | columns |
| List of column names, in insertion order. | |
| std::vector< std::string > | index |
| Optional index labels for the rows (if set). | |
| std::array< int, 2 > | shape = {0,0} |
| Shape of the DataFrame: {nRows, nCols}. | |
Simple column-oriented data structure with basic analysis utilities.
The DataFrame class stores columns as Series<T>, where T is typically int, double or std::string. Internally, columns are held in a map:
Column types are tracked via a CSVOptions instance, which also controls CSV export behavior (presence of index, etc.).
Supported features include:
Definition at line 61 of file DataFrame.h.
|
inline |
Default constructor.
Constructs an empty DataFrame with an empty index.
Definition at line 93 of file DataFrame.h.
| void DataFrame::_set_csv_options | ( | const CSVOptions & | options | ) |
Internal helper to set CSV options from an external source.
This copies the hasIndex flag and the columnTypes mapping, if provided. Intended for use by CSV readers or DataFrame methods that construct new DataFrames (e.g. head/tail).
| options | Options to copy into this DataFrame. |
Definition at line 238 of file DataFrame.cpp.
| void DataFrame::addColumn | ( | const std::string & | colName | ) |
Adds a new empty column of type T.
Creates a new Series<T> with the given name and registers it in the internal column map. The column type is also recorded in csvOptions.columnTypes.
| T | Value type of the column. |
| colName | Name of the new column. |
| void DataFrame::addValueToColumn | ( | const std::string & | colName, |
| const T & | value | ||
| ) |
Appends a value to an existing column.
The column must already exist and be of type T. If the column's size exceeds the current number of rows, the DataFrame row count and shape are updated accordingly.
| T | Value type of the column. |
| colName | Name of the target column. |
| value | Value to append. |
| std::invalid_argument | if the column does not exist. |
| T DataFrame::at | ( | const std::string & | idxValue, |
| const std::string & | colName | ||
| ) | const |
Label-based access to a cell (index label, column name).
The DataFrame must have an index set (via setIndex). The method searches the index for idxValue and returns the cell at the corresponding row and column.
| T | Expected type of the column. |
| idxValue | Row label to look up in the index. |
| colName | Name of the column. |
| std::invalid_argument | if the index is not set or if the label or column is not found. |
| void DataFrame::describe | ( | ) | const |
Prints a summary for all numeric columns.
For each column whose type in csvOptions is int or double, describeColumn() is called. Non-numeric columns are reported as ignored.
Definition at line 141 of file DataFrame.cpp.
| void DataFrame::describeColumn | ( | const std::string & | colName | ) | const |
Prints a statistical summary for a single numeric column.
The summary includes:
| T | Numeric type of the column (e.g. int or double). |
| colName | Name of the column to describe. |
| std::invalid_argument | if the column does not exist. |
| std::runtime_error | if the series is empty. |
Returns a copy of a column as a Series<T>.
| T | Value type of the column. |
| colName | Name of the column. |
| std::invalid_argument | if the column does not exist or is not of type T. |
| const std::vector< std::string > & DataFrame::getColumnNames | ( | ) | const |
Returns the list of column names.
Definition at line 66 of file DataFrame.cpp.
| const std::vector< std::string > & DataFrame::getIndex | ( | ) | const |
Returns the current index labels.
| std::runtime_error | if the index is not set. |
Definition at line 206 of file DataFrame.cpp.
| size_t DataFrame::getRowCount | ( | ) | const |
Returns the number of rows in the DataFrame.
Definition at line 70 of file DataFrame.cpp.
| DataFrame DataFrame::head | ( | size_t | n = 5 | ) | const |
Returns a new DataFrame with the first n rows.
Column metadata and csvOptions are propagated; index is truncated consistently if present.
| n | Number of rows to keep (clamped to available rows). |
Definition at line 74 of file DataFrame.cpp.
Positional access to a cell (row index, column name).
| T | Expected type of the column. |
| row | Zero-based row index. |
| colName | Name of the column. |
| std::invalid_argument | if the column does not exist. |
| std::out_of_range | if the row index is invalid. |
Accessor for a column as a modifiable Series<T>.
If the column does not exist yet, it is created as an empty Series<T> with the given name.
| T | Column value type. |
| colName | Name of the column. |
| void DataFrame::print | ( | ) | const |
Prints the DataFrame to std::cout in a tabular format.
Uses csvOptions.columnTypes to determine how to print each column (int, double, std::string). Index labels are printed in the first column if present.
Definition at line 27 of file DataFrame.cpp.
| void DataFrame::setIndex | ( | const std::vector< std::string > & | newIndex | ) |
Sets the index labels for all rows.
The size of newIndex must match the current number of rows (unless the DataFrame is still empty). The underlying Series<T> of each column is updated to share the same index.
| newIndex | Vector of labels to use as row index. |
| std::invalid_argument | if the size does not match nRows. |
Definition at line 214 of file DataFrame.cpp.
| DataFrame DataFrame::tail | ( | size_t | n = 5 | ) | const |
Returns a new DataFrame with the last n rows.
Column metadata and csvOptions are propagated; index is truncated consistently if present.
| n | Number of rows to keep (clamped to available rows). |
Definition at line 109 of file DataFrame.cpp.
| void DataFrame::to_csv | ( | const std::string & | filename | ) |
Serializes the DataFrame to a CSV file.
The header line contains the column names. If csvOptions.hasIndex is true, an "Index" column is written first and each row begins with its index (here: the integer row position).
Column types come from csvOptions.columnTypes and must be known (int, double, std::string) for all columns.
| filename | Path to the target CSV file. |
| std::runtime_error | on I/O errors or missing type info. |
Definition at line 156 of file DataFrame.cpp.
| std::vector<std::string> DataFrame::columns |
List of column names, in insertion order.
Definition at line 76 of file DataFrame.h.
| std::vector<std::string> DataFrame::index |
Optional index labels for the rows (if set).
Definition at line 79 of file DataFrame.h.
| std::array<int, 2> DataFrame::shape = {0,0} |
Shape of the DataFrame: {nRows, nCols}.
shape[0] is the number of rows, shape[1] the number of columns.
Definition at line 86 of file DataFrame.h.