15 #ifndef CORE_UTIL_CSV_READER_H_
16 #define CORE_UTIL_CSV_READER_H_
35 std::cout <<
"Error: " << file <<
" does not exist!" << std::endl;
38 rapidcsv::LabelParams labels(skip);
39 rapidcsv::SeparatorParams separator;
40 rapidcsv::ConverterParams converter(
true);
41 doc_ = rapidcsv::Document(file, labels, separator, converter);
48 std::vector<T>
GetColumn(
const std::string& column_name) {
49 return doc_.GetColumn<T>(column_name);
54 return doc_.GetCell<T>(col, row);
65 std::vector<std::string> ids =
doc_.GetColumn<std::string>(column_name);
70 template <
typename T =
float,
typename Lambda>
72 for (
auto val : GetColumn<T>(column_name)) {
73 if (!std::isnan(val)) {
80 std::cout <<
"Filename\t\t: " <<
filename_ << std::endl;
81 std::cout <<
"Row count\t\t: " <<
num_rows_ << std::endl;
82 std::cout <<
"Column count\t\t: " <<
num_cols_ << std::endl;
83 auto num_bad_entries =
85 std::cout <<
"Bad entries\t\t: " << num_bad_entries << std::endl;
Reads in a CSV file using rapidcsv.
std::string GetColumnName(size_t idx)
std::vector< T > GetColumn(const std::string &column_name)
void ForEachEntryInColumn(const std::string &column_name, Lambda lambda)
std::vector< bool > bad_entries_
size_t GetNumEntries(const std::string &column_name)
T GetCell(size_t col, size_t row)
CSVReader(const std::string &file, int skip=0)
std::vector< std::string > GetColumnNames()
bool FileExists(const std::string &file_name)