Signature | Description | Parameters |
---|---|---|
template<typename T, typename F, typename ... Ts> void remove_data_by_sel(const char *name, F &sel_functor) const; |
It removes data rows by boolean filtering selection via the sel_functor (e.g. a functor, function, or lambda). Each element of the named column along with its corresponding index is passed to the sel_functor. If sel_functor returns true, that row will be removed. The signature of sel_fucntor: bool ()(const IndexType &, const T &)NOTE: If the selection logic results in empty column(s), the empty column(s) will _not_ be padded with NaN's. You can always call make_consistent() afterwards to make all columns into consistent length |
T: Type of the named column F: Type of the selecting functor Ts: The list of types for all columns. A type should be specified only once name: Name of the data column sel_functor: A reference to the selecting functor |
template<typename T1, typename T2, typename F, typename ... Ts> void remove_data_by_sel(const char *name1, const char *name2, F &sel_functor) const; |
This does the same function as above remove_data_by_sel() but operating on two columns. The signature of sel_fucntor: bool ()(const IndexType &, const T1 &, const T2 &) |
T1: Type of the first named column T2: Type of the second named column F: Type of the selecting functor Ts: The list of types for all columns. A type should be specified only once name1: Name of the first data column name2: Name of the second data column sel_functor: A reference to the selecting functor |
template<typename T1, typename T2, typename T3, typename F, typename ... Ts> void remove_data_by_sel(const char *name1, const char *name2, const char *name3, F &sel_functor) const; |
This does the same function as above remove_data_by_sel() but operating on three columns. The signature of sel_fucntor: bool ()(const IndexType &, const T1 &, const T2 &, const T3 &) |
T1: Type of the first named column T2: Type of the second named column T3: Type of the third named column F: Type of the selecting functor Ts: The list of types for all columns. A type should be specified only once name1: Name of the first data column name2: Name of the second data column name3: Name of the third data column sel_functor: A reference to the selecting functor |
static void test_remove_data_by_sel() { std::cout << "\nTesting remove_data_by_sel() ..." << std::endl; std::vector<unsigned long> idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456 }; std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 }; std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 }; std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 }; std::vector<double> d4 = { 22, 23, 24, 25 }; std::vector<std::string> s1 = { "11", "22", "33", "ee", "ff", "gg", "ll" }; MyDataFrame df; auto shape = df.shape(); assert(shape.first == 0); assert(shape.second == 0); 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_str", s1)); df.load_column("col_4", std::move(d4), nan_policy::dont_pad_with_nans); shape = df.shape(); assert(shape.first == 7); assert(shape.second == 5); MyDataFrame df2 = df; auto functor = [](const unsigned long &, const double &val)-> bool { return (val >= 5); }; df.remove_data_by_sel<double, decltype(functor), double, std::string>("col_1", functor); assert(df.get_index().size() == 4); assert(df.get_column<double>("col_1").size() == 4); assert(df.get_column<std::string>("col_str").size() == 4); assert(df.get_column<double>("col_4").size() == 4); assert(df.get_index()[0] == 123450); assert(df.get_index()[2] == 123452); assert(df.get_column<double>("col_2")[1] == 9); assert(df.get_column<std::string>("col_str")[1] == "22"); assert(df.get_column<std::string>("col_str")[2] == "33"); assert(df.get_column<double>("col_1")[1] == 2); assert(df.get_column<double>("col_1")[2] == 3); assert(df.get_column<double>("col_4")[3] == 25); auto functor2 = [](const unsigned long &, const double &val1, const double &val2, const std::string val3)-> bool { return (val1 >= 5 || val2 == 15 || val3 == "33"); }; df2.remove_data_by_sel<double, double, std::string, decltype(functor2), double, std::string>("col_1", "col_3", "col_str", functor2); assert(df2.get_index().size() == 2); assert(df2.get_column<double>("col_1").size() == 2); assert(df2.get_column<std::string>("col_str").size() == 2); assert(df2.get_column<double>("col_4").size() == 2); assert(df2.get_index()[0] == 123451); assert(df2.get_index()[1] == 123453); assert(df2.get_column<double>("col_2")[0] == 9); assert(df2.get_column<double>("col_2")[1] == 11); assert(df2.get_column<double>("col_4")[0] == 23); assert(df2.get_column<double>("col_4")[1] == 25); assert(df2.get_column<std::string>("col_str")[0] == "22"); assert(df2.get_column<std::string>("col_str")[1] == "ee"); assert(df2.get_column<double>("col_1")[0] == 2); assert(df2.get_column<double>("col_1")[1] == 4); }