| Signature | Description | Parameters |
|---|---|---|
template<hashable_equal T, typename ... Ts> void sort_freq(const char *name, sort_spec dir, bool ignore_index = false); |
Sort the DataFrame by the frequency of data points in the named column If name equals DF_INDEX_COL_NAME, it sorts by index. Otherwise it sorts by the named column. If two frequencies are equal, sorting will be based on the value of the data points. NOTE: The order within the same frequency block is implementation dependent. NOTE: Sort first calls make_consistent() that may add nan values to data columns. nan values make sorting nondeterministic. |
T: Type of the by_name column. You always of the specify this type, even if it is being sorted to the default index Ts: The list of types for all columns. A type should be specified only once. name: The name of a column or string DF_INDEX_COL_NAME. dir: Direction of sorting, ascending or descending ignore_index: If true, index column won't be sorted |
template<hashable_equal T, typename ... Ts> std::future<void> sort_freq_async(const char *name, sort_spec dir, bool ignore_index = false); |
This is the asynchronous version that returns a std::future. Please see above for details |
static void test_sort_freq() { std::cout << "\nTesting sort_freq( ) ..." << std::endl; StrDataFrame ibm; try { ibm.read("IBM.csv", io_format::csv2); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; ::exit(-1); } auto fut = ibm.sort_freq_async<double, double, long>("IBM_Close", sort_spec::desce); fut.get(); assert((ibm.get_index()[0] == "2000-12-22")); assert((std::fabs(ibm.get_column<double>("IBM_Low")[0] - 84.5) < 0.01)); assert((std::fabs(ibm.get_column<double>("IBM_Close")[0] - 89.0) < 0.01)); assert((ibm.get_column<long>("IBM_Volume")[0] == 9514000)) ; assert((ibm.get_index()[7] == "2002-04-19")); assert((std::fabs(ibm.get_column<double>("IBM_High")[7] - 90.03) < 0.01)); assert((std::fabs(ibm.get_column<double>("IBM_Close")[7] - 89.0) < 0.01)); assert((ibm.get_column<long>("IBM_Volume")[7] == 9273200)) ; assert((ibm.get_index()[55] == "2010-01-06")); assert((std::fabs(ibm.get_column<double>("IBM_High")[55] - 131.49) < 0.01)); assert((std::fabs(ibm.get_column<double>("IBM_Close")[55] - 130.0) < 0.01)); assert((ibm.get_column<long>("IBM_Volume")[55] == 5605300)) ; assert((ibm.get_index()[58] == "2008-07-22")); assert((std::fabs(ibm.get_column<double>("IBM_Open")[58] - 127.5) < 0.01)); assert((std::fabs(ibm.get_column<double>("IBM_Close")[58] - 130.0) < 0.01)); assert((ibm.get_column<long>("IBM_Volume")[58] == 11428600)) ; assert((ibm.get_index()[4973] == "2002-09-05")); assert((std::fabs(ibm.get_column<double>("IBM_Open")[4973] - 72.73) < 0.01)); assert((std::fabs(ibm.get_column<double>("IBM_Close")[4973] - 72.18) < 0.01)); assert((ibm.get_column<long>("IBM_Volume")[4973] == 6467700)) ; assert((ibm.get_index()[5030] == "2002-10-09")); assert((std::fabs(ibm.get_column<double>("IBM_Open")[5030] - 56.05) < 0.01)); assert((std::fabs(ibm.get_column<double>("IBM_Close")[5030] - 55.07) < 0.01)); assert((ibm.get_column<long>("IBM_Volume")[5030] == 12156000)) ; }