Signature | Description | Parameters |
---|---|---|
template<typename T, typename V> DataFrame transpose(IndexVecType &&indices, const V &new_col_names) const; |
It transposes the data in the DataFrame. The transpose is only defined for DataFrame's that have a single data type. |
T: The single type for all data columns V: The type of string vector specifying the new names for new columns after transpose indices: A vector on indices for the new transposed DataFrame. Its length must equal the number of rows in this DataFrame. Otherwise an exception is thrown new_col_names: A vector of strings, specifying the column names for the new transposed DataFrame. Its length must equal the number of rows in this DataFrame. Otherwise an exception is thrown |
static void test_transpose() { std::cout << "\nTesting transpose() ..." << std::endl; std::vector<unsigned long> idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 }; std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 }; std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 }; std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 }; std::vector<double> d4 = { 22, 23, 24, 25 }; MyDataFrame df; df.load_data(std::move(idx), std::make_pair("col_1", d1), std::make_pair("col_2", d2), std::make_pair("col_3", d3), std::make_pair("col_4", d4)); std::vector<unsigned long> tidx = { 100, 101, 102, 104 }; std::vector<const char *> tcol_names = { "tcol_1", "tcol_2", "tcol_3", "tcol_4", "tcol_5", "tcol_6", "tcol_7" }; MyDataFrame tdf = df.transpose<double>(std::move(tidx), tcol_names); std::cout << "Original DataFrame:" << std::endl; df.write<std::ostream, unsigned long, double>(std::cout); std::cout << "Transposed DataFrame:" << std::endl; tdf.write<std::ostream, unsigned long, double>(std::cout); }