Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameTransformVisitors.h> template<typename T, typename I = unsigned long> struct ClipVisitor; |
This is a transformer visitor. It means the column(s) passed to this visitor is not read-only and its values may change This visitor sets any column value greater than upper to upper and any value smaller than lower to lower. The get_result() method returns the number of items changed. ClipVisitor(const T &upper, const T &lower) |
T: Column data type I: Index type |
static void test_ClipVisitor() { std::cout << "\nTesting ClipVisitor{ } ..." << std::endl; MyDataFrame df; std::vector<unsigned long> idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; std::vector<double> dblvec = { 0.0, 15.0, 14.0, 15.0, 1.0, 12.0, 11.0, 8.0, 15.0, 6.0, sqrt(-1), 4.0, 14.0, 14.0, 20.0}; std::vector<int> intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 }; std::vector<std::string> strvec = { "zz", "bb", "zz", "ww", "ee", "ff", "gg", "zz", "ii", "jj", "kk", "ll", "mm", "ee", "" }; df.load_data(std::move(idxvec), std::make_pair("dbl_col", dblvec), std::make_pair("str_col", strvec)); df.load_column("int_col", std::move(intvec), nan_policy::dont_pad_with_nans); ClipVisitor<double> clip (14, 5); auto result = df.visit<double>("dbl_col", clip).get_result(); assert(result == 7); assert(df.get_column<double>("dbl_col")[0] == 5.0); assert(df.get_column<double>("dbl_col")[1] == 14.0); assert(df.get_column<double>("dbl_col")[2] == 14.0); assert(df.get_column<double>("dbl_col")[4] == 5.0); assert(df.get_column<double>("dbl_col")[5] == 12.0); }