https://hosseinmoein.github.io/DataFrame/se in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Hossein Moein and/or the DataFrame nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
← Back to Documentations| Signature | Description | Parameters |
|---|---|---|
template<typename ... Ts> void void self_rotate(std::size_t periods, shift_policy sp); |
It rotates all the columns in self up, down, left, or right based on shift_policy. The index column remains unchanged. If user rotates with periods that is larger than the column length, the behavior is undefined. |
Ts: The list of types for all columns. A type should be specified only once. periods: Number of periods to rotate shift_policy: Specifies the direction (i.e. up/down) to rotate |
template<typename ... Ts> StdDataFrame<I> void rotate(std::size_t periods, shift_policy sp); |
It is exactly the same as self_rotate, but it leaves self unchanged and returns a new DataFrame with columns rotated. |
static void test_rotating_up_down() { std::cout << "\nTesting Rotating Up/Down ..." << std::endl; std::vector<unsigned long> idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 }; std::vector<double> d1 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0 }; std::vector<int> i1 = { 22, 23, 24, 25, 99 }; std::vector<std::string> s1 = { "qqqq", "wwww", "eeee", "rrrr", "tttt", "yyyy", "uuuu", "iiii", "oooo", "pppp", "2222", "aaaa", "dddd", "ffff" }; MyDataFrame df; df.load_data(std::move(idx), std::make_pair("dbl_col", d1), std::make_pair("int_col", i1), std::make_pair("str_col", s1)); std::cout << "Original DF:" << std::endl; df.write<std::ostream, double, int, std::string>(std::cout); auto rudf = df.rotate<double, int, std::string>(3, shift_policy::up); std::cout << "Rotated Up DF:" << std::endl; rudf.write<std::ostream, double, int, std::string>(std::cout); auto rddf = df.rotate<double, int, std::string>(3, shift_policy::down); std::cout << "Rotated Down DF:" << std::endl; rddf.write<std::ostream, double, int, std::string>(std::cout); }