Signature | Description | Parameters |
---|---|---|
template<typename ... Ts> DataFrame<I> get_data(const std::vector<const char *> col_names) const; |
This returns a DataFrame with index and col_names copied from the original DataFrame |
Ts: List types of col_names col_names: List of column names |
template<typename ... Ts> View get_view(const std::vector<const char *> col_names); |
It behaves like get_data(), but it returns a View. A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified. NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc. |
Ts: List types of col_names col_names: List of column names |
template<typename ... Ts> ConstView get_view(const std::vector<const char *> col_names) const; |
Same as above view, but it returns a const view. You can not change data in const views. But if the data is changed in the original DataFrame or through another view, it is refelcted in the const view. |
Ts: List types of col_names col_names: List of column names |
static void test_get_data() { std::cout << "\nTesting get_[data|view]() ..." << std::endl; StlVecType<unsigned long> idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; StlVecType<double> d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 }; StlVecType<double> d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 }; StlVecType<int> i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 }; 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)); auto df2 = df.get_data<double, int>({ "col_1", "col_4"}); assert((! df2.has_column("col_2"))); assert((! df2.has_column("col_3"))); assert((df2.get_column<double>("col_1")[11] == 12)); assert((df2.get_column<int>("col_4")[8] == 2)); assert((df2.get_index()[3] == 123453)); typedef MyDataFrame::View MyDataFrameView; typedef MyDataFrame::ConstView MyDataFrameConstView; const MyDataFrame &const_df = df; MyDataFrameView df3 = df.get_view<double, int>({ "col_1", "col_4"}); MyDataFrameConstView const_df3 = const_df.get_view<double, int>({ "col_1", "col_4"}); assert((! df3.has_column("col_2"))); assert((! df3.has_column("col_3"))); assert((df3.get_column<double>("col_1")[11] == 12)); assert((df3.get_column<int>("col_4")[8] == 2)); assert((df3.get_index()[3] == 123453)); df3.get_index()[3] = 100; df3.get_column<int>("col_4")[8] = 101; df3.get_column<double>("col_1")[11] = 102.2; assert((df3.get_column<double>("col_1")[11] == 102.2)); assert((df3.get_column<int>("col_4")[8] == 101)); assert((df3.get_index()[3] == 100)); assert((df.get_column<double>("col_1")[11] == 102.2)); assert((df.get_column<int>("col_4")[8] == 101)); assert((df.get_index()[3] == 100)); assert((const_df3.get_column<double>("col_1")[11] == 102.2)); assert((const_df3.get_column<int>("col_4")[8] == 101)); assert((const_df3.get_index()[3] == 100)); }