Vince's CSV Parser
csv::CSVStat Class Reference

Class for calculating statistics from CSV files and in-memory sources. More...

#include <csv_stat.hpp>

Public Types

using FreqCount = std::unordered_map< std::string, size_t >
 
using TypeCount = std::unordered_map< DataType, size_t >
 

Public Member Functions

std::vector< long double > get_mean () const
 Return current means.
 
std::vector< long double > get_variance () const
 Return current variances.
 
std::vector< long double > get_mins () const
 Return current mins.
 
std::vector< long double > get_maxes () const
 Return current maxes.
 
std::vector< FreqCount > get_counts () const
 Get counts for each column.
 
std::vector< TypeCount > get_dtypes () const
 Get data type counts for each column.
 
std::vector< std::string > get_col_names () const
 
 CSVStat (csv::string_view filename, CSVFormat format=CSVFormat::guess_csv())
 Calculate statistics for an arbitrarily large file. More...
 
 CSVStat (std::stringstream &source, CSVFormat format=CSVFormat())
 Calculate statistics for a CSV stored in a std::stringstream.
 

Detailed Description

Class for calculating statistics from CSV files and in-memory sources.

Example

#include "csv.hpp"
int main(int argc, char** argv) {
using namespace csv;
if (argc < 2) {
std::cout << "Usage: " << argv[0] << " [file]" << std::endl;
exit(1);
}
std::string filename = argv[1];
CSVStat stats(filename);
auto col_names = stats.get_col_names();
auto min = stats.get_mins(), max = stats.get_maxes(),
means = stats.get_mean(), vars = stats.get_variance();
for (size_t i = 0; i < col_names.size(); i++) {
std::cout << col_names[i] << std::endl
<< "Min: " << min[i] << std::endl
<< "Max: " << max[i] << std::endl
<< "Mean: " << means[i] << std::endl
<< "Var: " << vars[i] << std::endl;
}
return 0;
}
CSVStat(csv::string_view filename, CSVFormat format=CSVFormat::guess_csv())
Calculate statistics for an arbitrarily large file.
Definition: csv_stat.cpp:13
The all encompassing namespace.

Definition at line 18 of file csv_stat.hpp.

Constructor & Destructor Documentation

◆ CSVStat()

csv::CSVStat::CSVStat ( csv::string_view  filename,
CSVFormat  format = CSVFormat::guess_csv() 
)

Calculate statistics for an arbitrarily large file.

When this constructor is called, CSVStat will process the entire file iteratively. Once finished, methods like get_mean(), get_counts(), etc... can be used to retrieve statistics.

Definition at line 13 of file csv_stat.cpp.


The documentation for this class was generated from the following files: