Back to Documentations

Signature Description Parameters
template<arithmetic T, typename ... Ts>
void
remove_data_by_stdev(const char *col_name,
                     T above_stdev,
                     T below_stdev);
This calculates the mean and standard deviation of the named column. All data rows above and below the thresholds will be removed.

NOTE: Type T must support arithmetic operations
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
above_stdev: Above standard deviation threshold where data will be removed
below_stdev: Below standard deviation threshold where data will be removed
static void test_remove_data_by_stdev()  {

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

    typedef StdDataFrame64<std::string> StrDataFrame;

    StrDataFrame    df;

    try  {
        df.read("SHORT_IBM.csv", io_format::csv2);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
    }

    StrDataFrame    df2 = df;

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

    df.remove_data_by_stdev<double, double, long>("IBM_Close", 0.25, -0.5);
    view.remove_data_by_stdev<double, double, long>("IBM_Close", 0.25, -0.5);

    assert(df.get_index().size() == 570);
    assert(view.get_index().size() == 570);
    assert(view.get_column<double>("IBM_Open").size() == 570);
    assert(view.get_column<long>("IBM_Volume").size() == 570);
    assert(df.get_column<double>("IBM_Low").size() == 570);
    assert(df.get_column<long>("IBM_Volume").size() == 570);
    assert(df.get_index()[500] == "2019-04-08");
    assert(view.get_index()[101] == "2016-04-26");
    assert(view.get_column<double>("IBM_Open")[45] == 142.600006);
    assert(df.get_column<long>("IBM_Volume")[300] == 4300500);
}

C++ DataFrame