Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
DataFrame.h
Go to the documentation of this file.
1#ifndef DATAFRAME_H
2#define DATAFRAME_H
3
4#include <unordered_map>
5#include <string>
6#include <vector>
7#include <memory>
8#include <stdexcept>
9#include <fstream>
10#include <array>
11
12#include "Series.h"
13#include "CSVOptions.h"
14
33std::ostream& operator<<(std::ostream& os, const std::vector<std::string>& vec);
34
40std::ostream& operator<<(std::ostream& os, const std::array<int,2>& vec);
41
61class DataFrame {
62private:
64 std::unordered_map<std::string, std::shared_ptr<void>> columns_map;
65
67 size_t nRows = 0;
68
70 CSVOptions csvOptions;
71
73 std::vector<int> size;
74public:
76 std::vector<std::string> columns;
77
79 std::vector<std::string> index;
80
86 std::array<int, 2> shape = {0,0};
87
93 DataFrame() : index(std::vector<std::string>()) {}
94
105 template < typename T>
106 void addColumn(const std::string& colName);
107
121 template <typename T>
122 void addValueToColumn(const std::string& colName, const T& value);
123
135 template <typename T>
136 T iat(size_t row, const std::string& colName) const;
137
153 template <typename T>
154 T at(const std::string& idxValue, const std::string& colName) const;
155
166 template <typename T>
167 Series<T>& operator[](const std::string& colName);
168
176 void print() const;
177
181 const std::vector<std::string>& getColumnNames() const;
182
186 size_t getRowCount() const;
187
197 DataFrame head(size_t n = 5) const;
198
208 DataFrame tail(size_t n = 5) const;
209
223 template <typename T>
224 void describeColumn(const std::string& colName) const;
225
233 void describe() const;
234
245 template <typename T>
246 Series<T> getColumn(const std::string& colName) const;
247
260 void setIndex(const std::vector<std::string>& newIndex);
261
269 const std::vector<std::string>& getIndex() const;
270
285 void to_csv(const std::string& filename);
286
296 void _set_csv_options(const CSVOptions& options);
297};
298
299#include "DataFrame.tpp"
300
301#endif // DATAFRAME_H
Configuration holder for CSV import/export of a DataFrame.
std::ostream & operator<<(std::ostream &os, const std::vector< std::string > &vec)
Stream output helper for a vector of strings.
Definition DataFrame.cpp:4
Simple one-dimensional data container with basic statistics.
Simple column-oriented data structure with basic analysis utilities.
Definition DataFrame.h:61
void describeColumn(const std::string &colName) const
Prints a statistical summary for a single numeric column.
void print() const
Prints the DataFrame to std::cout in a tabular format.
Definition DataFrame.cpp:27
DataFrame tail(size_t n=5) const
Returns a new DataFrame with the last n rows.
const std::vector< std::string > & getIndex() const
Returns the current index labels.
void addValueToColumn(const std::string &colName, const T &value)
Appends a value to an existing column.
DataFrame head(size_t n=5) const
Returns a new DataFrame with the first n rows.
Definition DataFrame.cpp:74
Series< T > & operator[](const std::string &colName)
Accessor for a column as a modifiable Series<T>.
DataFrame()
Default constructor.
Definition DataFrame.h:93
T at(const std::string &idxValue, const std::string &colName) const
Label-based access to a cell (index label, column name).
void _set_csv_options(const CSVOptions &options)
Internal helper to set CSV options from an external source.
void describe() const
Prints a summary for all numeric columns.
std::array< int, 2 > shape
Shape of the DataFrame: {nRows, nCols}.
Definition DataFrame.h:86
Series< T > getColumn(const std::string &colName) const
Returns a copy of a column as a Series<T>.
void addColumn(const std::string &colName)
Adds a new empty column of type T.
size_t getRowCount() const
Returns the number of rows in the DataFrame.
Definition DataFrame.cpp:70
const std::vector< std::string > & getColumnNames() const
Returns the list of column names.
Definition DataFrame.cpp:66
void to_csv(const std::string &filename)
Serializes the DataFrame to a CSV file.
std::vector< std::string > index
Optional index labels for the rows (if set).
Definition DataFrame.h:79
std::vector< std::string > columns
List of column names, in insertion order.
Definition DataFrame.h:76
void setIndex(const std::vector< std::string > &newIndex)
Sets the index labels for all rows.
T iat(size_t row, const std::string &colName) const
Positional access to a cell (row index, column name).
Generic one-dimensional container of values with optional string index.
Definition Series.h:41
Hash specialization for SymbolId<Tag>.
Definition BlockName.h:353
double T(double x)
Wilson coefficient T(x).
Options describing how to interpret or write CSV data.
Definition CSVOptions.h:31