Back to Documentations

Signature Description Parameters
template<typename T, typename F>
size_type
count(const char *col_name, F &&functor) const requires
std::invocable<F, const IndexType &, const T &> &&
std::same_as<std::invoke_result_t<F, const IndexType &, const T &>, bool>;
This passes every datapoint in the named column to the functor along with its corresponding index datapoint. It counts and returns the number of times functor returns true.
The signature of fucntor:
    bool ()(const IndexType &, const T &)
        
T: Type of the named column
F: Type of the selecting functor
col_name: Name of the data column
functor: A reference to the selecting functor
template<typename T1, typename T2, typename F>
size_type
count(const char *col_name1, const char *col_name2,
      F &&functor) const requires
std::invocable<F, const IndexType &, const T1 &, const T2 &> &&
std::same_as<std::invoke_result_t<F, const IndexType &,
                                  const T1 &, const T2 &>, bool>;
This is the same as above count but operates on two data 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
name1: Name of the first data column
name2: Name of the second data column
functor: A reference to the selecting functor
template<typename T1, typename T2, typename T3, typename F>
size_type
count(const char *col_name1, const char *col_name2, const char *col_name3,
      F &&functor) const requires
std::invocable<F, const IndexType &,
               const T1 &, const T2 &, const T3 &> &&
std::same_as<std::invoke_result_t<F, const IndexType &,
                                  const T1 &, const T2 &, const T3 &>, bool>;
This is the same as above count but operates on three data 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
name1: Name of the first data column
name2: Name of the second data column
name3: Name of the third data column
functor: A reference to the selecting functor
template<typename T1, typename T2, typename T3, typename T4, typename F>
size_type
count(const char *col_name1, const char *col_name2,
      const char *col_name3, const char *col_name4,
      F &&functor) const requires
std::invocable<F, const IndexType &,
               const T1 &, const T2 &, const T3 &, const T4 &> &&
std::same_as<std::invoke_result_t<F, const IndexType &,
                                  const T1 &, const T2 &,
                                  const T3 &, const T4 &>, bool>;
This is the same as above count but operates on four data columns.
The signature of sel_fucntor:
    bool ()(const IndexType &,
            const T1 &, const T2 &, const T3 &, const T4 &)
        
T1: Type of the first named column
T2: Type of the second named column
T3: Type of the third named column
T4: Type of the fourth named column
F: Type of the selecting functor
name1: Name of the first data column
name2: Name of the second data column
name3: Name of the third data column
name4: Name of the fourth data column
functor: A reference to the selecting functor
tatic void test_count()  {

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

    ULDataFrame df;

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

    const auto  count1 = df.count<double>("FORD_Close",
                                          [](const unsigned long &, const double &close)  {
                                              return (close > 10.0);
                                          });

    assert(count1 == 4900);

    const auto  count2 = df.count<double, double, double, long>("FORD_Close", "FORD_Open", "FORD_Low", "FORD_Volume",
                                                                [](const unsigned long &, const double &close, const double &open,
                                                                   const double &low, const long &volume)  {
                                                                    return (close > 10.0 && open > 10.0 && low > 10.0 && volume > 40'000'000L);
                                                                });

    assert(count2 == 953);
}

C++ DataFrame