Class used to handle data read from csv files. More...
#include <dataFrame.hpp>
Public Member Functions | |
DataFrame (std::string file_name, char delimiter, bool first_row_is_column_names, int primery_key=0) | |
Constructor. More... | |
std::string | operator() (const int col, const int row) |
Reads cell in c-th column and r-th row. More... | |
std::string | operator() (const std::string col, const int row) |
Reads cell in column named c and r-th row. More... | |
std::string | operator() (const std::string col, const std::string row) |
Reads cell in column name and row holding primary key r. More... | |
std::vector< std::string > | operator() (int col) |
Reads column basic on column number. More... | |
std::vector< std::string > | operator() (std::string col) |
Reads column basic on column number. More... | |
double | getDouble (const int col, const int row) |
Reads cell in c-th column and r-th row. More... | |
double | getDouble (const std::string col, const int row) |
Reads cell in column named c and r-th row. More... | |
double | getDouble (const std::string col, const std::string row) |
Reads cell in column name and row holding primary key r. More... | |
Date | getDate (const int col, const int row, Date::Format fmt) |
Reads cell in c-th column and r-th row. More... | |
Date | getDate (const std::string col, const int row, Date::Format fmt) |
Reads cell in column named c and r-th row. More... | |
Date | getDate (const std::string col, const std::string row, Date::Format fmt) |
Reads cell in column name and row holding primary key r. More... | |
std::vector< std::string > | getColumnNames () const |
Returns column names as vector of strings. More... | |
std::vector< std::string > | getPrimaryKeys () const |
Returns primary keys as vector of strings. More... | |
std::map< std::string, std::string > | getRow (int row) const |
Returns row in form of std::map. More... | |
void | append (const DataEntryClerk &) |
adds data stored by DataEntryClerk More... | |
void | append (const DataFrame &) |
Appends one data frame to another. More... | |
void | print (int n_rows=-1) |
Prints DataFrame. More... | |
void | printToCsv (std::string file_name, char delimiter= ';') |
prints DataFrame to csv file More... | |
int | getNumberOfRows () const |
Returns number of rows. More... | |
int | getNumberOfColumns () const |
Returns number of columns. More... | |
template<class T > | |
SmartPointer< T > | getObject (const int col, const int row) |
Reads cell in c-th column and r-th row. More... | |
template<class T > | |
SmartPointer< T > | getObject (const std::string col, const int row) |
Reads cell in column named c and r-th row. More... | |
template<class T > | |
SmartPointer< T > | getObject (const std::string col, const std::string row) |
Reads cell in column name and row holding primary key r. More... | |
template<class T > | |
T | getValue (const int col, const int row) |
Reads cell in c-th column and r-th row. More... | |
template<class T > | |
T | getValue (const std::string col, const int row) |
Reads cell in column named c and r-th row. More... | |
template<class T > | |
T | getValue (const std::string col, const std::string row) |
Reads cell in column name and row holding primary key r. More... | |
template<class T > | |
DataFrame | filter (int col, T filter) |
Filter the data frame basing on data hold in column. More... | |
template<class T > | |
DataFrame | filter (std::string col, T filter) |
Filter the data frame basing on data hold in column. More... | |
Private Member Functions | |
void | parseFile (std::string file_name, char delimiter) |
parse csv file, result of method is saved in DataFrame::data_ More... | |
void | createColumnNames (bool first_row) |
creates columns names basing on the first row of csv file More... | |
Private Attributes | |
std::vector< std::vector< std::string > > | data_ |
Holds data as 2d table of strings. More... | |
std::map< std::string, int > | column_names_ |
Maps column name to column number. More... | |
std::map< std::string, int > | primary_key_ |
Maps row name to row number. More... | |
int | ncols_ = 0 |
number of columns More... | |
int | nrows_ = 0 |
number of rows More... | |
Friends | |
std::ostream & | operator<< (std::ostream &, DataFrame &) |
Overloads stream operator. More... | |
Detailed Description
Class used to handle data read from csv files.
Class enables to load the csv file and read it contents. One can access the single cell or read whole columns. Class allows to choose cell using column and row numbers or, if defined, column names and primary keys.
Constructor & Destructor Documentation
julian::DataFrame::DataFrame | ( | std::string | file_name, |
char | delimiter, | ||
bool | first_row_is_column_names, | ||
int | primery_key = 0 |
||
) |
Constructor.
- Parameters
-
file_name File name that will be read. delimiter Separation sign in csv file. first_row_is_column_names True if first row contains column names. primery_key Defines which column contains primary key of the table.
Create DataFrame on the basis of provided file.
Member Function Documentation
void julian::DataFrame::append | ( | const DataEntryClerk & | entry | ) |
adds data stored by DataEntryClerk
Data stored in DataEntryClerK:data_ are added. If new columns are added, old rows are filled with "." representing missing.
void julian::DataFrame::append | ( | const DataFrame & | appended | ) |
Appends one data frame to another.
|
private |
creates columns names basing on the first row of csv file
- Remarks
- Method used by constructor. Bad practice, so better keep the method non-virtual.
DataFrame julian::DataFrame::filter | ( | int | col, |
T | filter | ||
) |
Filter the data frame basing on data hold in column.
- Parameters
-
col column identification filter Functor with overloaded operator bool operator()(std::string), if functor returns true row is added to DataFrame that is returned by the method
DataFrame julian::DataFrame::filter | ( | std::string | col, |
T | filter | ||
) |
Filter the data frame basing on data hold in column.
- Parameters
-
col column identification filter Functor with overloaded operator bool operator()(std::string), if functor returns true row is added to DataFrame that is returned by the method
- Note
- May be used only when column names were defined.
std::vector< std::string > julian::DataFrame::getColumnNames | ( | ) | const |
Returns column names as vector of strings.
Date julian::DataFrame::getDate | ( | const int | col, |
const int | row, | ||
Date::Format | fmt | ||
) |
Reads cell in c-th column and r-th row.
- Parameters
-
col column name row row number fmt Date format (compare Date::Format)
- Returns
- Returns content of cell as a date formatted according to fmt
Date julian::DataFrame::getDate | ( | const std::string | col, |
const int | row, | ||
Date::Format | fmt | ||
) |
Reads cell in column named c and r-th row.
- Parameters
-
col column name row row number fmt Date format (compare Date::Format)
- Returns
- Returns content of cell as a date formatted according to fmt
- Note
- May be used only when column names were defined.
Date julian::DataFrame::getDate | ( | const std::string | col, |
const std::string | row, | ||
Date::Format | fmt | ||
) |
Reads cell in column name and row holding primary key r.
- Parameters
-
col column name row row number fmt Date format (compare Date::Format)
- Returns
- Returns content of cell as a date formatted according to fmt
- Note
- May be used only when column names and primary keys were defined.
double julian::DataFrame::getDouble | ( | const int | col, |
const int | row | ||
) |
Reads cell in c-th column and r-th row.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell as double
double julian::DataFrame::getDouble | ( | const std::string | col, |
const int | row | ||
) |
Reads cell in column named c and r-th row.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell as double
- Note
- May be used only when column names were defined.
double julian::DataFrame::getDouble | ( | const std::string | col, |
const std::string | row | ||
) |
Reads cell in column name and row holding primary key r.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell as double
- Note
- May be used only when column names and primary keys were defined.
int julian::DataFrame::getNumberOfColumns | ( | ) | const |
Returns number of columns.
int julian::DataFrame::getNumberOfRows | ( | ) | const |
Returns number of rows.
SmartPointer< T > julian::DataFrame::getObject | ( | const int | col, |
const int | row | ||
) |
Reads cell in c-th column and r-th row.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell. Method uses ObjectFactory to transform string into object.
SmartPointer< T > julian::DataFrame::getObject | ( | const std::string | col, |
const int | row | ||
) |
Reads cell in column named c and r-th row.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell. Method uses ObjectFactory to transform string into object.
- Note
- May be used only when column names were defined.
SmartPointer< T > julian::DataFrame::getObject | ( | const std::string | col, |
const std::string | row | ||
) |
Reads cell in column name and row holding primary key r.
- Parameters
-
col column name row row name
- Returns
- Returns content of cell as string Method uses ObjectFactory to transform string into object.
- Note
- May be used only when column names and primary keys were defined.
std::vector< std::string > julian::DataFrame::getPrimaryKeys | ( | ) | const |
Returns primary keys as vector of strings.
std::map< std::string, std::string > julian::DataFrame::getRow | ( | int | row | ) | const |
Returns row in form of std::map.
T julian::DataFrame::getValue | ( | const int | col, |
const int | row | ||
) |
Reads cell in c-th column and r-th row.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell. Method uses ValueFactory to transform string into enumeration.
T julian::DataFrame::getValue | ( | const std::string | col, |
const int | row | ||
) |
Reads cell in column named c and r-th row.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell. Method uses ValueFactory to transform string into enumeration.
- Note
- May be used only when column names were defined.
T julian::DataFrame::getValue | ( | const std::string | col, |
const std::string | row | ||
) |
Reads cell in column name and row holding primary key r.
- Parameters
-
col column name row row name
- Returns
- Returns content of cell as string Method uses ValueFactory to transform string into enumeration.
- Note
- May be used only when column names and primary keys were defined.
std::string julian::DataFrame::operator() | ( | const int | col, |
const int | row | ||
) |
Reads cell in c-th column and r-th row.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell as string
std::string julian::DataFrame::operator() | ( | const std::string | col, |
const int | row | ||
) |
Reads cell in column named c and r-th row.
- Parameters
-
col column name row row number
- Returns
- Returns content of cell as string
- Note
- May be used only when column names were defined.
std::string julian::DataFrame::operator() | ( | const std::string | col, |
const std::string | row | ||
) |
Reads cell in column name and row holding primary key r.
- Parameters
-
col column name row row name
- Returns
- Returns content of cell as string
- Note
- May be used only when column names and primary keys were defined.
std::vector< std::string > julian::DataFrame::operator() | ( | int | col | ) |
Reads column basic on column number.
- Parameters
-
col column number
- Returns
- Returns column as vector of string
std::vector< std::string > julian::DataFrame::operator() | ( | std::string | col | ) |
Reads column basic on column number.
- Parameters
-
col column number
- Returns
- Returns column as vector of string
- Note
- May be used only when column names were defined.
|
private |
parse csv file, result of method is saved in DataFrame::data_
- Remarks
- Method used by constructor. Bad practice, so better keep the method non-virtual.
- Bug:
- Function reads EOL sign All but last rows are read with EOL sign. This cause the problem with comparing signs. Below if statement solves the problem by cutting of the last char if it is a EOL. Not sure if this is a save solution.
void julian::DataFrame::print | ( | int | n_rows = -1 | ) |
Prints DataFrame.
- Examples:
- DataFrameExample.cpp.
void julian::DataFrame::printToCsv | ( | std::string | file_name, |
char | delimiter = ';' |
||
) |
prints DataFrame to csv file
- Parameters
-
file_name delimiter separator used in csv file, by default set to semicolon
Friends And Related Function Documentation
|
friend |
Overloads stream operator.
This overloaded operator enables to print the curve on the console.
Member Data Documentation
|
private |
Maps column name to column number.
|
private |
Holds data as 2d table of strings.
|
private |
number of columns
|
private |
number of rows
|
private |
Maps row name to row number.
The documentation for this class was generated from the following files:
- C:/Unix/home/OEM/jULIAN/src/utils/dataFrame.hpp
- C:/Unix/home/OEM/jULIAN/src/utils/dataFrame.cpp