| Signature | Description | Parameters |
|---|---|---|
template<EnumType E, typename T, typename F> std::unordered_map<E, size_type> class_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 &>, E>; |
For this you must define an Enum class that can classify the data in the named column with its options. This function will pass the datapoints in the named column to the functor which returns an Enum value for each datapoint. Then it will count the number of instances of each option in the Enum. The returned result is a map of Enum options to the number of instances. The signature of fucntor:
E ()(const IndexType &, const T &)
|
E: An enum class type to classify the values in the named columns T: Type of the named column F: Type of the classifying functor col_name: Name of the data column functor: A reference to the classifying functor |
template<EnumType E, typename T1, typename T2, typename F> std::unordered_map<E, size_type> class_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 &>, E>; |
This is the same as above class_count but operates on two data columns. The signature of sel_fucntor:
E ()(const IndexType &, const T1 &, const T2 &)
|
E: An enum class type to classify the values in the named columns T1: Type of the first named column T2: Type of the second named column F: Type of the classifying functor name1: Name of the first data column name2: Name of the second data column functor: A reference to the classifying functor |
template<EnumType E, typename T1, typename T2, typename T3, typename F> std::unordered_map<E, size_type> class_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 &>, E>; |
This is the same as above class_count but operates on three data columns. The signature of sel_fucntor:
E ()(const IndexType &, const T1 &, const T2 &, const T3 &)
|
E: An enum class type to classify the values in the named columns 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 classifying 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 classifying functor |
template<EnumType E, typename T1, typename T2, typename T3, typename T4, typename F> std::unordered_map<E, size_type> class_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 &>, E>; |
This is the same as above class_count but operates on four data columns. The signature of sel_fucntor:
E ()(const IndexType &,
const T1 &, const T2 &, const T3 &, const T4 &)
|
E: An enum class type to classify the values in the named columns 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 classifying 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 classifying functor |
enum class FordDataTypes : int { invalid = 0, grey = 1, blue = 2, red = 3, white = 4, }; static void test_class_count() { std::cout << "\nTesting class_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); } auto result = df.class_count<FordDataTypes, 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) -> FordDataTypes { if (close > 0 && open > 0 && low > 0 && volume > 0) { if (close < 1.5) return (FordDataTypes::grey); else if (close < 5.5) return (FordDataTypes::blue); else if (close < 20.5) return (FordDataTypes::red); else return (FordDataTypes::white); } return (FordDataTypes::invalid); }); assert(result[FordDataTypes::invalid] == 0); assert(result[FordDataTypes::grey] == 1232); assert(result[FordDataTypes::blue] == 2877); assert(result[FordDataTypes::red] == 7279); assert(result[FordDataTypes::white] == 877); assert((df.get_index().size() == (0 + 1232 + 2877 + 7279 + 877))); }