GLAMERDOC++
Gravitational Lensing Code Library
Loading...
Searching...
No Matches
Utilities::DataFrame< T > Class Template Reference

class for impoting data from a csv file and allowing label string lookup like a data frame. More...

#include <utilities_slsim.h>

Public Member Functions

 DataFrame (std::string datafile, size_t MaxNumber=1000000, char comment_char='#', char deliniator=',', std::string replace="\\N", std::function< bool(std::vector< T > &)> accept=[](std::vector< T > &v){return true;})
 
void input (std::string datafile, size_t MaxNumber=1000000, char comment_char='#', char deliniator=',', std::string replace="\\N", std::function< bool(std::vector< T > &)> accept=[](std::vector< T > &v){return true;})
 
void pop (std::string colname)
 remove a column
 
std::vector< T > & operator[] (const std::string &label)
 returns column by name
 
void add_column (const std::string &name, const std::vector< T > &vec)
 add a column to the data frame. This does a copy.
 
std::vector< T > & operator[] (int i)
 returns column by number
 
std::vector< std::string > labels () const
 returns labels of the columns from the data file
 
void sortby (std::string name)
 
void shuffle (Utilities::RandomNumbers_NR &ran)
 
size_t number_of_rows ()
 
size_t number_of_columns ()
 

Public Attributes

std::vector< std::vector< T > > data
 

Detailed Description

template<typename T>
class Utilities::DataFrame< T >

class for impoting data from a csv file and allowing label string lookup like a data frame.

The accept function can be used to limit the amount of data added. If there is an object, a, used to make this selection this can be done like [&a](str::vector<T> &v}{return a.itsok(v[3],v[4]);} where v corresponds to a row in the data file in order.

Entries that throw an exception when converting to T are replaced with -500

Constructor & Destructor Documentation

◆ DataFrame()

template<typename T >
Utilities::DataFrame< T >::DataFrame ( std::string datafile,
size_t MaxNumber = 1000000,
char comment_char = '#',
char deliniator = ',',
std::string replace = "\\N",
std::function< bool(std::vector< T > &)> accept = [](std::vector<T> &v){return true;} )
inline
Parameters
datafileinput catalog file in csv format
MaxNumbermaximum number of entries read
comment_charcomment charactor for header
deliniatordeliniator between values
replacereplace this string with zeros
acceptfunction that determines if a row should be accepted

Member Function Documentation

◆ input()

template<typename T >
void Utilities::DataFrame< T >::input ( std::string datafile,
size_t MaxNumber = 1000000,
char comment_char = '#',
char deliniator = ',',
std::string replace = "\\N",
std::function< bool(std::vector< T > &)> accept = [](std::vector<T> &v){return true;} )
inline
Parameters
datafileinput catalog file in csv format
MaxNumbermaximum number of entries read
comment_charcomment charactor for header
deliniatordeliniator between values
replacereplace this string with zeros
acceptfunction that determines if a row should be accepted

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