Signature | Description | Parameters |
---|---|---|
template<typename OLD_T1, typename OLD_T2, typename NEW_T, typename F> void consolidate(const char *old_col_name1, const char *old_col_name2, const char *new_col_name, F &functor, bool delete_old_cols = true); |
This method feeds old_col_name1 and old_col_name2 of types OLD_T1 and OLD_T2 to functor which returns a std::vector Functor "functor" should implement the logic of consolidating two columns into one. Functor signature is: template<typename ITR1, typename ITR2> std::vector<NEW_T> (IndexVecType::const_iterator idx_begin, IndexVecType::const_iterator idx_end, ITR1 col1_begin, ITR1 col1_end, ITR2 col2_begin, ITR2 col2_end); Where ITR[12] are iterators for columns 1 and 2. They are iterators of std::vector.NOTE: This method could not be called from views. |
OLD_T1: Type of existing column named old_col_name1 OLD_T2: Type of existing column named old_col_name2 NEW_T: Type of the new column new_col_name which is the consolidation of the two existing columns F: Type of the consildating functor old_col_name1: Name of the first existing column old_col_name2: Name of the second existing column new_col_name: Name of the new consolidated column functor: Consolidating functor delete_old_cols: If true, old columns will be removed |
template<typename OLD_T1, typename OLD_T2, typename OLD_T3, typename NEW_T, typename F> void consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, const char *new_col_name, F &functor, bool delete_old_cols = true); |
This is the same as above consolidate(), but it consolidates 3 columns into one. Functor signature is: template<typename ITR1, typename ITR2, typename ITR3> std::vector<NEW_T> (IndexVecType::const_iterator idx_begin, IndexVecType::const_iterator idx_end, ITR1 col1_begin, ITR1 col1_end, ITR2 col2_begin, ITR2 col2_end, ITR3 col3_begin, ITR3 col3_end); Where ITR[123] are iterators for columns 1, 2, and 3. They are iterators of std::vector.NOTE: This method could not be called from views. |
OLD_T1: Type of existing column named old_col_name1 OLD_T2: Type of existing column named old_col_name2 OLD_T3: Type of existing column named old_col_name3 NEW_T: Type of the new column new_col_name which is the consolidation of the two existing columns F: Type of the consildating functor old_col_name1: Name of the first existing column old_col_name2: Name of the second existing column old_col_name3: Name of the third existing column new_col_name: Name of the new consolidated column functor: Consolidating functor delete_old_cols: If true, old columns will be removed |
template<typename OLD_T1, typename OLD_T2, typename OLD_T3, typename OLD_T4, typename NEW_T, typename F> void consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, const char *old_col_name4, const char *new_col_name, F &functor, bool delete_old_cols = true); |
This is the same as above consolidate(), but it consolidates 4 columns into one. Functor signature is: template<typename ITR1, typename ITR2, typename ITR3, typename ITR4> std::vector<NEW_T> (IndexVecType::const_iterator idx_begin, IndexVecType::const_iterator idx_end, ITR1 col1_begin, ITR1 col1_end, ITR2 col2_begin, ITR2 col2_end, ITR3 col3_begin, ITR3 col3_end, ITR4 col4_begin, ITR4 col4_end); Where ITR[1234] are iterators for columns 1, 2, 3, and 4. They are iterators of std::vector.NOTE: This method could not be called from views. |
OLD_T1: Type of existing column named old_col_name1 OLD_T2: Type of existing column named old_col_name2 OLD_T3: Type of existing column named old_col_name3 OLD_T4: Type of existing column named old_col_name4 NEW_T: Type of the new column new_col_name which is the consolidation of the two existing columns F: Type of the consildating functor old_col_name1: Name of the first existing column old_col_name2: Name of the second existing column old_col_name3: Name of the third existing column old_col_name4: Name of the forth existing column new_col_name: Name of the new consolidated column functor: Consolidating functor delete_old_cols: If true, old columns will be removed |
template<typename OLD_T1, typename OLD_T2, typename OLD_T3, typename OLD_T4, typename OLD_T5, typename NEW_T, typename F> void consolidate(const char *old_col_name1, const char *old_col_name2, const char *old_col_name3, const char *old_col_name4, const char *old_col_name5, const char *new_col_name, F &functor, bool delete_old_cols = true); |
This is the same as above consolidate(), but it consolidates 5 columns into one. Functor signature is: template<typename ITR1, typename ITR2, typename ITR3, typename ITR4, typename ITR5> std::vector<NEW_T> (IndexVecType::const_iterator idx_begin, IndexVecType::const_iterator idx_end, ITR1 col1_begin, ITR1 col1_end, ITR2 col2_begin, ITR2 col2_end, ITR3 col3_begin, ITR3 col3_end, ITR4 col4_begin, ITR4 col4_end, ITR5 col5_begin, ITR5 col5_end); Where ITR[12345] are iterators for columns 1, 2, 3, 4, and 5. They are iterators of std::vector.NOTE: This method could not be called from views. |
OLD_T1: Type of existing column named old_col_name1 OLD_T2: Type of existing column named old_col_name2 OLD_T3: Type of existing column named old_col_name3 OLD_T4: Type of existing column named old_col_name4 OLD_T5: Type of existing column named old_col_name5 NEW_T: Type of the new column new_col_name which is the consolidation of the two existing columns F: Type of the consildating functor old_col_name1: Name of the first existing column old_col_name2: Name of the second existing column old_col_name3: Name of the third existing column old_col_name4: Name of the forth existing column old_col_name5: Name of the fifth existing column new_col_name: Name of the new consolidated column functor: Consolidating functor delete_old_cols: If true, old columns will be removed |
static std::vector<std::string> add_columns(MyDataFrame::IndexVecType::const_iterator idx_begin, MyDataFrame::IndexVecType::const_iterator idx_end, std::vector<double>::const_iterator b_citer1, std::vector<double>::const_iterator e_citer1, std::vector<double>::const_iterator b_citer2, std::vector<double>::const_iterator e_citer2, std::vector<std::string>::const_iterator b_citer3, std::vector<std::string>::const_iterator e_citer3) { const std::size_t col_s = std::min ({ std::distance(b_citer1, e_citer1), std::distance(b_citer2, e_citer2), std::distance(b_citer3, e_citer3) }); std::vector<std::string> result (col_s); for (std::size_t i = 0; i < col_s; ++i) result[i] = *(b_citer3 + i) + std::to_string(*(b_citer1 + i) + *(b_citer2 + i)); return (result); } // -------------------------------------- static void test_consolidate() { std::cout << "\nTesting consolidate( ) ..." << std::endl; MyDataFrame df; std::vector<unsigned long> idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; std::vector<double> dblvec = { 0.0, 15.0, 14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 9.0, 10.0 }; std::vector<double> dblvec2 = { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0 }; std::vector<int> intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; std::vector<std::string> strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; df.load_data(std::move(idxvec), std::make_pair("dbl_col", dblvec), std::make_pair("dbl_col_2", dblvec2), std::make_pair("str_col", strvec)); df.load_column("int_col", std::move(intvec), nan_policy::dont_pad_with_nans); df.consolidate<double, double, std::string, std::string> ("dbl_col", "dbl_col_2", "str_col", "new_str_col", add_columns, true); assert(! df.has_column("dbl_col")); assert(! df.has_column("dbl_col_2")); assert(! df.has_column("str_col")); assert(df.has_column("new_str_col")); const auto &new_str_col = df.get_column<std::string>("new_str_col"); const std::vector<const char *> actual = { "zz100.000000", "bb116.000000", "cc116.000000", "ww105.000000", "ee105.000000", "ff117.000000", "gg117.550000", "hh115.340000", "ii8.800000", "jj117.000000", "kk117.000000", "ll117.000000", "mm117.000000", "nn124.000000", "oo126.000000" }; for (size_t idx = 0; idx < actual.size(); ++idx) assert(new_str_col[idx] == actual[idx]); }