Back to Documentations

Signature Description Parameters
template<comparable T, typename ... Ts>
void
remove_top_n_data(const char *col_name, size_type n);
It removes data rows corresponding to n top rows of the named column.

NOTE Comparison operators (<, >, ==) must be well defined for type T.
T: Type of the named column
Ts: The list of types for all columns. A type should be specified only once
col_name: Name of the data column
n: Number of top rows
template<comparable T, typename ... Ts>
void
remove_bottom_n_data(const char *col_name, size_type n);
It removes data rows corresponding to n bottom rows of the named column.

NOTE Comparison operators (<, >, ==) must be well defined for type T.
T: Type of the named column
Ts: The list of types for all columns. A type should be specified only once
col_name: Name of the data column
n: Number of bottom rows
static void test_remove_top_n_data()  {

    std::cout << "\nTesting remove_top_n_data( ) ..." << std::endl;

    StlVecType<unsigned long>   idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123463 };
    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, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 10 };
    StlVecType<int>             i1 = { 22, 23, 24, 25, 99 };
    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));

    MyDataFrame df2 = df;

    auto    lbd = [](const unsigned long &, const double &val) -> bool { return (val < 100.0); };
    auto    view = df2.get_view_by_sel<double, decltype(lbd), double, int, std::string>("col_1", lbd);

    df.remove_top_n_data<double, int, double, std::string>("col_3", 4);
    view.remove_top_n_data<double, int, double, std::string>("col_3", 4);

    assert(df.get_index().size() == 10);
    assert(view.get_index().size() == 10);
    assert(df.get_column<double>("col_2").size() == 10);
    assert(view.get_column<double>("col_2").size() == 10);
    assert(df.get_column<int>("col_4").size() == 10);
    assert(view.get_column<int>("col_4").size() == 10);
    assert(df.get_index()[4] == 123457);
    assert(view.get_index()[4] == 123457);
    assert(df.get_column<double>("col_1")[6] == 10);
    assert(view.get_column<double>("col_1")[6] == 10);
    assert(df.get_column<int>("col_4")[2] == 24);
    assert(view.get_column<int>("col_4")[2] == 24);
}
// -----------------------------------------------------------------------------

static void test_remove_bottom_n_data()  {

    std::cout << "\nTesting remove_bottom_n_data( ) ..." << std::endl;

    StlVecType<unsigned long>   idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123463 };
    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, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 10 };
    StlVecType<int>             i1 = { 22, 23, 24, 25, 99 };
    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));

    MyDataFrame df2 = df;

    auto    lbd = [](const unsigned long &, const double &val) -> bool { return (val < 100.0); };
    auto    view = df2.get_view_by_sel<double, decltype(lbd), double, int, std::string>("col_1", lbd);

    df.remove_bottom_n_data<double, int, double, std::string>("col_3", 4);
    view.remove_bottom_n_data<double, int, double, std::string>("col_3", 4);

    assert(df.get_index().size() == 10);
    assert(view.get_index().size() == 10);
    assert(df.get_column<double>("col_2").size() == 10);
    assert(view.get_column<double>("col_2").size() == 10);
    assert(df.get_column<int>("col_4").size() == 10);
    assert(view.get_column<int>("col_4").size() == 10);
    assert(df.get_index()[4] == 123454);
    assert(view.get_index()[4] == 123454);
    assert(df.get_column<double>("col_1")[6] == 7);
    assert(view.get_column<double>("col_1")[6] == 7);
    assert(df.get_column<int>("col_4")[2] == 24);
    assert(view.get_column<int>("col_4")[2] == 24);
}

C++ DataFrame