Signature | Description | Parameters |
---|---|---|
template<typename T, typename ITR> std::size_t load_column(const char *name, Index2D<const ITR &> range, nan_policy padding = nan_policy::pad_with_nans); |
It copies the data from iterators begin to end to the named column. If column does not exist, it will be created. If the column exist, it will be over written. Returns number of items loaded |
T: Type of data being copied ITR: Type of the iterator name: Name of the column range: The begin and end iterators for data padding: If true, it pads the data column with nan if it is shorter than the index column. |
template<typename> std::size_t load_column(const char *name, std::vector<T> &&data, nan_policy padding = nan_policy::pad_with_nans); |
It moves the data to the named column in DataFrame. If column does not exist, it will be created. If the column exist, it will be over written. Returns number of items loaded |
T: Type of data being copied ITR: Type of the iterator name: Name of the column data: Data vector range: The begin and end iterators for data padding: If true, it pads the data column with nan if it is shorter than the index column. |
template<typename> std::size_t load_column(const char *name, const std::vector<T> &data, nan_policy padding = nan_policy::pad_with_nans); |
It copies the data to the named column in DataFrame. If column does not exist, it will be created. If the column exist, it will be over written. Returns number of items loaded |
T: Type of data being copied ITR: Type of the iterator name: Name of the column data: Data vector range: The begin and end iterators for data padding: If true, it pads the data column with nan if it is shorter than the index column. |
template<typename> std::size_t load_align_column( const char *name, const std::vector<T> &&data, std::size_t interval, bool start_from_beginning, const T &null_value = get_nan<T>(), std::function<std::size_t (const IndexType &, const IndexType &)> diff_func = [](const IndexType &t_1, const IndexType &t) -> std::size_t { return (static_cast<std::size_t>(t - t_1)); }); |
This method creates a column similar to above, but it assumes data is bucketed (bar) values. That means the data vector contains statistical figure(s) for time buckets and must be aligned with the index column at bucket intervals. For example, index column is in minutes unit. And data vector is the sum of 5-minute buckets of some column, or some data set not present in DataFrame. The values in data vector will be aligned with the index column at every 5 minutes interval. The in-between values will be “null_value”. NOTE: The data vector must contain (index size / interval) number of values or less, if index has values per interval. Otherwise, data must contain appropriate number of values. NOTE: The index must be in ascending order |
T: Type of data being loaded name: Name of the column data: Data vector interval: Bucket interval measured in index units distance start_from_beginning: If true, the first data value will be associated with the first index value. If false, the first data value will be associated with index value interval away from the first index value null_value: The value to fill the new column in-between intervals. The default is T version of NaN. For None NaN'able types, it will be default value for T diff_func: Function to calculate distance between two index values |
static void test_load_align_column() { std::cout << "\nTesting load_align_column( ) ..." << std::endl; std::vector<unsigned long> idxvec = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 }; std::vector<int> intvec = { -1, 2, 3, 4, 5, 8, -6, 7, 11, 14, -9, 12, 13, 14, 15 }; std::vector<double> summary_vec = { 100, 200, 300, 400, 500 }; MyDataFrame df; df.load_data(std::move(idxvec), std::make_pair("int_col", intvec)); df.load_align_column("summary_col", std::move(summary_vec), 5, true); std::vector<double> summary_vec_2 = { 102, 202, 302, 402, 502 }; df.load_align_column("summary_col_2", std::move(summary_vec_2), 5, false); assert(df.get_column<double>("summary_col").size() == 28); assert(df.get_column<double>("summary_col_2").size() == 28); assert(df.get_column<double>("summary_col")[0] == 100); assert(std::isnan(df.get_column<double>("summary_col_2")[0])); assert(df.get_column<double>("summary_col")[5] == 200); assert(std::isnan(df.get_column<double>("summary_col")[6])); assert(df.get_column<double>("summary_col_2")[5] == 102); assert(df.get_column<double>("summary_col")[20] == 500); assert(df.get_column<double>("summary_col_2")[25] == 502); assert(std::isnan(df.get_column<double>("summary_col")[27])); assert(std::isnan(df.get_column<double>("summary_col")[26])); assert(std::isnan(df.get_column<double>("summary_col_2")[27])); assert(std::isnan(df.get_column<double>("summary_col_2")[26])); }