DataFrameRolling ================ .. cpp:class:: pandas::DataFrameRolling Window operation class for rolling/expanding calculations. Example ------- .. code-block:: cpp #include using namespace pandas; // Use DataFrameRolling DataFrameRolling obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``DataFrameRolling(const DataFrame& df, size_t window, size_t min_periods = 1, bool center = false)`` - pd_dataframe.h:12632 - Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``const DataFrame& get_df() const`` - const DataFrame& - pd_dataframe.h:12654 - Statistics ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``size_t min_periods() const`` - size_t - pd_dataframe.h:12652 - Aggregation ----------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame apply_to_columns(Func&& func) const`` - DataFrame - pd_dataframe.h:12690 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool center() const`` - bool - pd_dataframe.h:12653 - :ref:`View ` * - ``Rolling select_column(const std::string& col) const`` - Rolling - pd_dataframe.h:12656 - * - ``void set_custom_bounds(std::vector start, std::vector end)`` - void - pd_dataframe.h:12645 - * - ``void set_on_column(const std::string& col)`` - void - pd_dataframe.h:12643 - * - ``void set_time_window(std::vector timestamps, int64_t window_seconds, int closed = 0)`` - void - pd_dataframe.h:12635 - * - ``size_t window() const`` - size_t - pd_dataframe.h:12651 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-dataframerolling-center-0: .. dropdown:: center (pd_test_3_all.cpp:21005) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20995 :emphasize-lines: 11 auto alnum_result = s.str().isalnum(); if (alnum_result[0] != true || alnum_result[1] != true || alnum_result[2] != true || alnum_result[3] != false) { std::cout << " [FAIL] : isalnum() failed" << std::endl; throw std::runtime_error("pd_test_str_is_methods: isalnum() failed"); } std::cout << " -> tests passed" << std::endl; } // ============================================================================ // Test str().zfill(), str().center(), str().ljust(), str().rjust() // ============================================================================ void pd_test_str_padding() { std::cout << "========= Series.str().zfill/center/ljust/rjust() ======="; pandas::Series s({"1", "22", "333"}); auto zfill_result = s.str().zfill(5); if (zfill_result[0] != "00001" || zfill_result[1] != "00022" || zfill_result[2] != "00333") { std::cout << " [FAIL] : zfill() failed" << std::endl; .. _example-dataframerolling-window-1: .. dropdown:: window (pd_test_1_all.cpp:20977) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20967 :emphasize-lines: 11 } throw std::runtime_error("pd_test_expanding_corr failed: expanding corr values incorrect"); } std::cout << " -> tests passed" << std::endl; } void pd_test_expanding_skew() { std::cout << "========= Expanding skew ========================"; // Symmetric data: skew should be 0 at each expanding window (starting from 3) pandas::Series s({1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}); auto result = s.expanding().skew(); // First 2 should be NaN (need >= 3 values) // Symmetric expanding windows [1,2,3], [1,2,3,4], ... all have skew = 0 bool passed = std::isnan(result[0]) && std::isnan(result[1]) && std::abs(result[2] - 0.0) < 0.001 && std::abs(result[3] - 0.0) < 0.001 && std::abs(result[4] - 0.0) < 0.001;