openGPMP
Open Source Mathematics Package
|
#include <datatable.hpp>
Public Member Functions | |
DataTable () | |
DataTableStr | csv_read (std::string filename, std::vector< std::string > columns={}) |
Reads a CSV file and returns a DataTableStr parses CSV files and stores all data as strings. More... | |
void | csv_write () |
Write DataTable to a CSV file. More... | |
DataTableStr | tsv_read (std::string filename, std::vector< std::string > columns={}) |
Reads a TSV file and returns a DataTableStr parses TSV files and stores all data as strings. More... | |
DataTableStr | json_read (std::string filename, std::vector< std::string > objs={}) |
Reads a JSON file and returns a DataTableStr parses JSON files and stores all data as strings. More... | |
DataTableStr | datetime (std::string column_name, bool extract_year=true, bool extract_month=true, bool extract_time=false) |
Extracts date and time components from a timestamp column. More... | |
void | sort (const std::vector< std::string > &sort_columns, bool ascending=true) |
Sorts the rows of the DataTable based on specified columns. More... | |
std::vector< DataTableStr > | group_by (std::vector< std::string > group_by_columns) |
Groups the data by specified columns. More... | |
DataTableStr | first (const std::vector< gpmp::core::DataTableStr > &groups) const |
Gets the first element of each created group. More... | |
void | describe () |
Prints some information about the DataTable. More... | |
DataTableInt | str_to_int (DataTableStr src) |
Converts a DataTableStr to a DataTableInt. More... | |
DataTableDouble | str_to_double (DataTableStr src) |
Converts a DataTableStr to a DataTableDouble. More... | |
template<typename T > | |
void | display (std::pair< std::vector< T >, std::vector< std::vector< T >>> data, bool display_all=false) |
Sort a DataTable based on a specified column. More... | |
void | display (bool display_all=false) |
Overload function for display() defaults to displaying what is currently stored in a DataTable object. More... | |
DataTable () | |
DataTable constructor. Initializes column & row storage. More... | |
void | printData () |
TableType | csv_read_new (std::string filename, std::vector< std::string > columns={}) |
Reads a CSV file and returns a DataTableStr parses CSV files and stores all data as strings. More... | |
DataTableStr | csv_read (std::string filename, std::vector< std::string > columns) |
void | csv_write () |
Write DataTable to a CSV file. More... | |
DataTableStr | tsv_read (std::string filename, std::vector< std::string > columns={}) |
Reads a TSV file and returns a DataTableStr parses TSV files and stores all data as strings. More... | |
DataTableStr | json_read (std::string filename, std::vector< std::string > objs={}) |
Reads a JSON file and returns a DataTableStr parses JSON files and stores all data as strings. More... | |
void | drop (std::vector< std::string > column_name) |
Drop specified rows from a DataTable. More... | |
DataTableStr | datetime (std::string column_name, bool extract_year=true, bool extract_month=true, bool extract_time=false) |
Extracts date and time components from a timestamp column. More... | |
void | sort (const std::vector< std::string > &sort_columns, bool ascending=true) |
Sorts the rows of the DataTable based on specified columns. More... | |
std::vector< DataTableStr > | group_by (std::vector< std::string > group_by_columns) |
Groups the data by specified columns. More... | |
DataTableStr | first (const std::vector< gpmp::core::DataTableStr > &groups) const |
Gets the first element of each created group. More... | |
void | describe () |
Displays some information about the DataTable. More... | |
void | info () |
Displays data types and null vals for each column. More... | |
TableType | native_type (const std::vector< std::string > &skip_columns={}) |
Converts DataTable column's rows to their native types. Since the existing DataTable read/load related methods hone in on the DataTableStr type, there must be a way to get those types to their native formats. More... | |
DataType | inferType (const std::vector< std::string > &column) |
DataTableInt | str_to_int (DataTableStr src) |
Converts a DataTableStr to a DataTableInt. More... | |
DataTableDouble | str_to_double (DataTableStr src) |
Converts a DataTableStr to a DataTableDouble. More... | |
void | display (const TableType &data, bool display_all=false) |
Sort a DataTable based on a specified column. More... | |
void | display (bool display_all=false) |
Overload function for display() defaults to displaying what is currently stored in a DataTable object. More... | |
Private Attributes | |
std::vector< std::string > | headers_ |
std::vector< std::vector< std::string > > | rows_ |
std::vector< std::string > | new_headers_ |
std::vector< std::vector< std::string > > | data_ |
DataTableStr | original_data_ |
MixedType | rows_ |
MixedType | data_ |
Definition at line 76 of file datatable.hpp.
|
inline |
Definition at line 91 of file datatable.hpp.
|
inline |
DataTable constructor. Initializes column & row storage.
Definition at line 111 of file datatable_wip.hpp.
DataTableStr gpmp::core::DataTable::csv_read | ( | std::string | filename, |
std::vector< std::string > | columns | ||
) |
gpmp::core::TableType gpmp::core::DataTable::csv_read | ( | std::string | filename, |
std::vector< std::string > | columns = {} |
||
) |
Reads a CSV file and returns a DataTableStr parses CSV files and stores all data as strings.
filename | the path to the CSV file |
columns | optional vector of column names to read in, if empty all columns will be read in |
Definition at line 57 of file datatable.cpp.
References data_, and headers_.
Referenced by main(), and test_train().
TableType gpmp::core::DataTable::csv_read_new | ( | std::string | filename, |
std::vector< std::string > | columns = {} |
||
) |
Reads a CSV file and returns a DataTableStr parses CSV files and stores all data as strings.
filename | the path to the CSV file |
columns | optional vector of column names to read in, if empty all columns will be read in |
void gpmp::core::DataTable::csv_write | ( | ) |
Write DataTable to a CSV file.
void gpmp::core::DataTable::csv_write | ( | ) |
Write DataTable to a CSV file.
gpmp::core::DataTableStr gpmp::core::DataTable::datetime | ( | std::string | column_name, |
bool | extract_year = true , |
||
bool | extract_month = true , |
||
bool | extract_time = false |
||
) |
Extracts date and time components from a timestamp column.
column_name | The name of the timestamp column |
extract_year | If true, extract the year component |
extract_month | If true, extract the month component |
extract_time | If true, extract the time component |
Definition at line 147 of file datatable.cpp.
References _log_, ERROR, gpmp::core::Logger::log(), and year.
DataTableStr gpmp::core::DataTable::datetime | ( | std::string | column_name, |
bool | extract_year = true , |
||
bool | extract_month = true , |
||
bool | extract_time = false |
||
) |
Extracts date and time components from a timestamp column.
column_name | The name of the timestamp column |
extract_year | If true, extract the year component |
extract_month | If true, extract the month component |
extract_time | If true, extract the time component |
void gpmp::core::DataTable::describe | ( | ) |
Prints some information about the DataTable.
void gpmp::core::DataTable::describe | ( | ) |
Displays some information about the DataTable.
|
inline |
Overload function for display() defaults to displaying what is currently stored in a DataTable object.
display_all | Display all rows, defaults to false. |
Definition at line 316 of file datatable.hpp.
void gpmp::core::DataTable::display | ( | bool | display_all = false | ) |
void gpmp::core::DataTable::display | ( | const TableType & | data, |
bool | display_all = false |
||
) |
Sort a DataTable based on a specified column.
Displays a DataTable of type T with the option to display all or a subset of rows
T | The type of the DataTable to be displayed |
data | A pair of vectors representing the header and data rows of the DataTable |
display_all | A flag indicating whether to display all rows or just a subset |
Definition at line 196 of file datatable2.cpp.
|
inline |
Sort a DataTable based on a specified column.
Displays a DataTable of type T with the option to display all or a subset of rows
T | The type of the DataTable to be displayed |
data | A pair of vectors representing the header and data rows of the DataTable |
display_all | A flag indicating whether to display all rows or just a subset |
Definition at line 216 of file datatable.hpp.
void gpmp::core::DataTable::drop | ( | std::vector< std::string > | column_name | ) |
Drop specified rows from a DataTable.
gpmp::core::DataTableStr gpmp::core::DataTable::first | ( | const std::vector< gpmp::core::DataTableStr > & | groups | ) | const |
Gets the first element of each created group.
groups | Return type of gpmp::core::DataTable.group() |
Definition at line 317 of file datatable.cpp.
DataTableStr gpmp::core::DataTable::first | ( | const std::vector< gpmp::core::DataTableStr > & | groups | ) | const |
Gets the first element of each created group.
groups | Return type of gpmp::core::DataTable.group() |
std::vector< gpmp::core::DataTableStr > gpmp::core::DataTable::group_by | ( | std::vector< std::string > | group_by_columns | ) |
Groups the data by specified columns.
group_by_columns | The column names to group by |
Definition at line 250 of file datatable.cpp.
References _log_, ERROR, and gpmp::core::Logger::log().
std::vector<DataTableStr> gpmp::core::DataTable::group_by | ( | std::vector< std::string > | group_by_columns | ) |
Groups the data by specified columns.
group_by_columns | The column names to group by |
gpmp::core::DataType gpmp::core::DataTable::inferType | ( | const std::vector< std::string > & | column | ) |
Definition at line 135 of file datatable1.cpp.
References _log_, gpmp::core::dt_double, gpmp::core::dt_int32, gpmp::core::dt_str, INFO, is_double(), is_int(), and gpmp::core::Logger::log().
void gpmp::core::DataTable::info | ( | ) |
DataTableStr gpmp::core::DataTable::json_read | ( | std::string | filename, |
std::vector< std::string > | objs = {} |
||
) |
Reads a JSON file and returns a DataTableStr parses JSON files and stores all data as strings.
filename | the path to the JSON file |
objs | optional vector of JSON object names to read in, if empty all objects will be read in |
DataTableStr gpmp::core::DataTable::json_read | ( | std::string | filename, |
std::vector< std::string > | objs = {} |
||
) |
Reads a JSON file and returns a DataTableStr parses JSON files and stores all data as strings.
filename | the path to the JSON file |
objs | optional vector of JSON object names to read in, if empty all objects will be read in |
gpmp::core::TableType gpmp::core::DataTable::native_type | ( | const std::vector< std::string > & | skip_columns = {} | ) |
Converts DataTable column's rows to their native types. Since the existing DataTable read/load related methods hone in on the DataTableStr type, there must be a way to get those types to their native formats.
Definition at line 176 of file datatable1.cpp.
References _log_, gpmp::core::dt_double, gpmp::core::dt_int32, gpmp::core::dt_str, dt_to_str(), INFO, and gpmp::core::Logger::log().
|
inline |
Definition at line 116 of file datatable_wip.hpp.
void gpmp::core::DataTable::sort | ( | const std::vector< std::string > & | sort_columns, |
bool | ascending = true |
||
) |
Sorts the rows of the DataTable based on specified columns.
sort_columns | A vector of column names to sort by. |
ascending | If true, sort in ascending order; otherwise, sort in descending order, default is true. |
Definition at line 217 of file datatable.cpp.
void gpmp::core::DataTable::sort | ( | const std::vector< std::string > & | sort_columns, |
bool | ascending = true |
||
) |
Sorts the rows of the DataTable based on specified columns.
sort_columns | A vector of column names to sort by. |
ascending | If true, sort in ascending order; otherwise, sort in descending order, default is true. |
gpmp::core::DataTableDouble gpmp::core::DataTable::str_to_double | ( | DataTableStr | src | ) |
Converts a DataTableStr to a DataTableDouble.
src | A DataTableStr object to be converted |
Definition at line 370 of file datatable.cpp.
DataTableDouble gpmp::core::DataTable::str_to_double | ( | DataTableStr | src | ) |
Converts a DataTableStr to a DataTableDouble.
src | A DataTableStr object to be converted |
gpmp::core::DataTableInt gpmp::core::DataTable::str_to_int | ( | DataTableStr | src | ) |
Converts a DataTableStr to a DataTableInt.
src | The DataTableStr to convert |
Definition at line 347 of file datatable.cpp.
DataTableInt gpmp::core::DataTable::str_to_int | ( | DataTableStr | src | ) |
Converts a DataTableStr to a DataTableInt.
src | The DataTableStr to convert |
DataTableStr gpmp::core::DataTable::tsv_read | ( | std::string | filename, |
std::vector< std::string > | columns = {} |
||
) |
Reads a TSV file and returns a DataTableStr parses TSV files and stores all data as strings.
filename | the path to the TSV file |
columns | optional vector of column names to read in, if empty all columns will be read in |
DataTableStr gpmp::core::DataTable::tsv_read | ( | std::string | filename, |
std::vector< std::string > | columns = {} |
||
) |
Reads a TSV file and returns a DataTableStr parses TSV files and stores all data as strings.
filename | the path to the TSV file |
columns | optional vector of column names to read in, if empty all columns will be read in |
|
private |
Definition at line 85 of file datatable.hpp.
Referenced by csv_read(), DataTable(), display(), and printData().
|
private |
Definition at line 102 of file datatable_wip.hpp.
|
private |
Definition at line 79 of file datatable.hpp.
Referenced by csv_read(), DataTable(), display(), and printData().
|
private |
Definition at line 83 of file datatable.hpp.
|
private |
Definition at line 88 of file datatable.hpp.
|
private |
Definition at line 81 of file datatable.hpp.
|
private |
Definition at line 98 of file datatable_wip.hpp.