Signature | Description | Parameters |
---|---|---|
template<typename ... Ts> HeteroVector get_row(std::size_t row_num, const std::vector<const char *> &col_names) const; |
It returns the data in row row_num for columns in col_names. The order of data items in the returned vector is the same as order of columns on col_names. The first item in the returned vector is always the index value corresponding to the row_num It returns a HeteroVector which contains a different type for each column. |
Ts: The list of types for all columns. A type should be specified only once. row_num: The row number col_names: Names of columns to get data from. It also specifies the order of data in the returned vector |
template<typename ... Ts> HeteroVector get_row(std::size_t row_num) const; |
This is same as get_row() above. But it always includes all the columns in the returned row. The order is the column creation order. If you have rotated the columns, the creation order has changed. You can always use column_name_to_idx() and column_idx_to_name() methods. |
Ts: The list of types for all columns. A type should be specified only once. row_num: The row number |
static void test_get_row() { std::cout << "\nTesting get_row() ..." << std::endl; std::vector<unsigned long> idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; std::vector<double> d1 = { 1, 2, 3, 4, std::numeric_limits<double>::quiet_NaN(), 6, 7, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), 11, 12, 13, 14 }; std::vector<double> d2 = { 8, 9, 10, 11, 12, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), 20, 22, 23, 30, 31, std::numeric_limits<double>::quiet_NaN(), 1.89 }; std::vector<double> d3 = { 400.4, 16, 500.5, 18, 19, 16, std::numeric_limits<double>::quiet_NaN(), 0.34, 1.56, 0.34, 2.3, 0.34, std::numeric_limits<double>::quiet_NaN() }; std::vector<int> i1 = { 22, 11, 34, 25, std::numeric_limits<int>::quiet_NaN() }; MyDataFrame df; df.load_data(std::move(idx), std::make_pair("col_1", d1), std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_4", i1)); std::vector<std::string> s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "iiii", "oooo" }; df.load_column("col_str", std::move(s1), nan_policy::dont_pad_with_nans); std::vector<int> i2 = { 22, 11 }; df.load_column("col_int", std::move(i2), nan_policy::dont_pad_with_nans); std::cout << "Original DF:" << std::endl; df.write<std::ostream, int, double, std::string>(std::cout); std::vector<const char *> columns = {"col_1", "col_2", "col_3", "col_4", "col_str", "col_int"}; auto row2 = df.get_row<int, double, std::string>(2, columns); assert(row2.at<MyDataFrame::IndexType>(0) == 123452); assert(row2.at<double>(0) == 3.0); assert(row2.at<double>(1) == 10.0); assert(row2.at<double>(2) == 500.5); assert(row2.at<int>(0) == 34); assert(row2.at<int>(1) == 0); assert(row2.at<std::string>(0) == "eeee"); auto row3 = df.get_row<int, double, std::string>(3); assert(row3.at<MyDataFrame::IndexType>(0) == 123453); assert(row3.at<double>(0) == 4.0); assert(row3.at<double>(1) == 11.0); assert(row3.at<double>(2) == 18.0); assert(row3.at<int>(0) == 25); assert(row3.at<int>(1) == 0); assert(row3.at<std::string>(0) == "rrrr"); }