DataFrameGroupByResampler#
-
class pandas::DataFrameGroupByResampler#
pandas C++ class.
Example#
#include <pandas/pandas.h>
using namespace pandas;
// Use DataFrameGroupByResampler
DataFrameGroupByResampler obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
pd_groupby.h:4877 |
Missing Data#
Aggregation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
pd_groupby.h:4382 |
|
|
void |
pd_groupby.h:4561 |
|
|
const DataFrameGroupBy& |
pd_groupby.h:4883 |
|
|
static DataFrame |
pd_groupby.h:4543 |
|
|
DataFrameResampler |
pd_groupby.h:4419 |
Combining#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static void |
pd_groupby.h:4723 |
|
|
pd_groupby.h:4970 |
||
|
pd_groupby.h:4982 |
||
|
pd_groupby.h:5049 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::vector<std::vector<std::string>> |
pd_groupby.h:4642 |
|
|
std::vector<std::vector<std::string>> |
pd_groupby.h:4693 |
|
|
DatetimeIndex |
pd_groupby.h:4334 |
|
|
void |
pd_groupby.h:4625 |
|
|
pd_groupby.h:4535 |
||
|
void |
pd_groupby.h:4677 |
|
|
static void |
pd_groupby.h:4821 |
|
|
pd_groupby.h:4936 |
||
|
pd_groupby.h:5021 |
||
|
const std::string& |
pd_groupby.h:4885 |
|
|
DataFrame |
pd_groupby.h:4772 |
|
|
std::string |
pd_groupby.h:4311 |
|
|
pd_groupby.h:4457 |
||
|
std::string |
pd_groupby.h:4325 |
|
|
const std::string& |
pd_groupby.h:4884 |
|
|
const DateOffset& |
pd_groupby.h:4275 |
|
|
std::vector<std::vector<std::string>> |
pd_groupby.h:4391 |
|
|
std::vector<std::vector<std::string>> |
pd_groupby.h:4920 |
|
|
std::vector<std::vector<std::string>> |
pd_groupby.h:5006 |
|
|
DatetimeIndex |
pd_groupby.h:4854 |
|
|
const std::string& |
pd_groupby.h:4886 |
|
|
static GroupDateMap_ |
pd_groupby.h:4848 |
|
|
static void |
pd_groupby.h:4747 |
|
|
DatetimeIndex |
pd_groupby.h:4371 |
|
|
static std::string |
pd_groupby.h:4301 |
Code Examples#
The following examples are extracted from the test suite.
bfill (pd_test_1_all.cpp:23603)
23593 std::cout << "====================================== [OK] pd_test_equals test suite ========================== " << std::endl;
23594 return 0;
23595 }
23596
23597} // namespace dataframe_tests
23598// ------------------- pd_test_equals.cpp (end) -----------------------------
23599
23600// ------------------- pd_test_ffill_bfill.cpp (start) -----------------------------
23601// dataframe_tests/pd_test_ffill_bfill.cpp
23602// Test file for DataFrame.ffill() and DataFrame.bfill() methods
23603
23604#include <iostream>
23605#include <stdexcept>
23606#include <cmath>
23607#include <limits>
23608#include <map>
23609#include "../pandas/pd_dataframe.h"
23610
23611// CRITICAL: No using namespace directives
ffill (pd_test_1_all.cpp:23603)
23593 std::cout << "====================================== [OK] pd_test_equals test suite ========================== " << std::endl;
23594 return 0;
23595 }
23596
23597} // namespace dataframe_tests
23598// ------------------- pd_test_equals.cpp (end) -----------------------------
23599
23600// ------------------- pd_test_ffill_bfill.cpp (start) -----------------------------
23601// dataframe_tests/pd_test_ffill_bfill.cpp
23602// Test file for DataFrame.ffill() and DataFrame.bfill() methods
23603
23604#include <iostream>
23605#include <stdexcept>
23606#include <cmath>
23607#include <limits>
23608#include <map>
23609#include "../pandas/pd_dataframe.h"
23610
23611// CRITICAL: No using namespace directives
groupby (pd_test_1_all.cpp:11495)
11485 std::cout << "========= GroupBy basic =========================";
11486
11487 // Create DataFrame with category column
11488 std::map<std::string, std::vector<double>> data = {
11489 {"category", {1.0, 1.0, 2.0, 2.0, 2.0}},
11490 {"value", {10.0, 20.0, 30.0, 40.0, 50.0}}
11491 };
11492 pandas::DataFrame df(data);
11493
11494 // Test groupby
11495 auto grouped = df.groupby("category");
11496
11497 bool passed = grouped.ngroups() == 2;
11498 if (!passed) {
11499 std::cout << " [FAIL] : in pd_test_groupby_basic() : ngroups should be 2" << std::endl;
11500 throw std::runtime_error("pd_test_groupby_basic failed: ngroups should be 2");
11501 }
11502
11503 std::cout << " -> tests passed" << std::endl;
11504 }
arrays (pd_test_1_all.cpp:10642)
10632 std::cout << " -> tests passed" << std::endl;
10633}
10634
10635// ============================================================================
10636// Set Operations Tests
10637// ============================================================================
10638
10639void pd_test_extension_index_append() {
10640 std::cout << "========= append =========================";
10641
10642 // Use same categories for both arrays (required by CategoricalArray::concat)
10643 std::vector<std::string> cats = {"a", "b", "c", "d"};
10644 pandas::CategoricalArray arr1({"a", "b"}, cats);
10645 pandas::CategoricalIndex idx1(arr1);
10646
10647 pandas::CategoricalArray arr2({"c", "d"}, cats);
10648 pandas::CategoricalIndex idx2(arr2);
10649
10650 auto appended = idx1.append(idx2);
10651
10652 bool passed = (appended.size() == 4);
arrays (pd_test_1_all.cpp:10642)
10632 std::cout << " -> tests passed" << std::endl;
10633}
10634
10635// ============================================================================
10636// Set Operations Tests
10637// ============================================================================
10638
10639void pd_test_extension_index_append() {
10640 std::cout << "========= append =========================";
10641
10642 // Use same categories for both arrays (required by CategoricalArray::concat)
10643 std::vector<std::string> cats = {"a", "b", "c", "d"};
10644 pandas::CategoricalArray arr1({"a", "b"}, cats);
10645 pandas::CategoricalIndex idx1(arr1);
10646
10647 pandas::CategoricalArray arr2({"c", "d"}, cats);
10648 pandas::CategoricalIndex idx2(arr2);
10649
10650 auto appended = idx1.append(idx2);
10651
10652 bool passed = (appended.size() == 4);
closed (pd_test_1_all.cpp:1903)
1893// ============================================================================
1894void test_constructors() {
1895 std::cout << "========= IntervalArray: constructors ======================= ";
1896
1897 // Default constructor
1898 pandas::IntervalArrayFloat64 empty;
1899 if (empty.size() != 0) {
1900 std::cout << "[FAIL] : in test_constructors() : default constructor size" << std::endl;
1901 return;
1902 }
1903 if (empty.closed() != pandas::IntervalClosed::Right) {
1904 std::cout << "[FAIL] : in test_constructors() : default closure" << std::endl;
1905 return;
1906 }
1907
1908 // Constructor from left/right arrays
1909 numpy::NDArray<numpy::float64> left(std::vector<size_t>{3});
1910 numpy::NDArray<numpy::float64> right(std::vector<size_t>{3});
1911 left.setElementAt({0}, 0.0); right.setElementAt({0}, 1.0);
1912 left.setElementAt({1}, 1.0); right.setElementAt({1}, 2.0);
1913 left.setElementAt({2}, 2.0); right.setElementAt({2}, 3.0);
freq (pd_test_1_all.cpp:8233)
8223 std::cout << "========= freq property ===============================";
8224
8225 std::vector<std::optional<numpy::datetime64>> values = {
8226 numpy::datetime64(0LL, numpy::DateTimeUnit::Nanosecond),
8227 numpy::datetime64(86400000000000LL, numpy::DateTimeUnit::Nanosecond) // 1 day
8228 };
8229 pandas::DatetimeArray arr(values);
8230 pandas::DatetimeMixinIndex idx(arr);
8231
8232 // Default freq is nullopt or inferred
8233 auto f = idx.freq();
8234 std::string fs = idx.freqstr();
8235
8236 bool passed = true; // freq may or may not be set
8237 if (!passed) {
8238 std::cout << " [FAIL] : in pd_test_datetime_mixin_freq()" << std::endl;
8239 throw std::runtime_error("pd_test_datetime_mixin_freq failed");
8240 }
8241
8242 std::cout << " -> tests passed" << std::endl;
8243}
idx (pd_test_1_all.cpp:5266)
5256 throw std::runtime_error("pd_test_categorical_index_default_constructor failed");
5257 }
5258
5259 std::cout << " -> tests passed" << std::endl;
5260}
5261
5262void pd_test_categorical_index_array_constructor() {
5263 std::cout << "========= array constructor ===========================";
5264
5265 pandas::CategoricalArray arr({"apple", "banana", "apple", "cherry"});
5266 pandas::CategoricalIndex idx(arr, "fruits");
5267
5268 bool passed = (idx.size() == 4 && !idx.empty() &&
5269 idx.name().has_value() && *idx.name() == "fruits" &&
5270 idx.inferred_type() == "categorical");
5271 if (!passed) {
5272 std::cout << " [FAIL] : in pd_test_categorical_index_array_constructor()" << std::endl;
5273 throw std::runtime_error("pd_test_categorical_index_array_constructor failed");
5274 }
5275
5276 std::cout << " -> tests passed" << std::endl;
label (pd_test_4_all.cpp:4935)
4925// Helper: compare and report
4926// ----------------------------------------------------------------------------
4927static void check_str(const std::string& label,
4928 const std::string& expected,
4929 const std::string& actual) {
4930 int _f = 0;
4931 pandas_tests::check_str_ws(label, expected, actual, _f);
4932 if (_f > 0) throw std::runtime_error(label + ": str mismatch");
4933}
4934
4935// Slugify a python compare-test label ("a.b.c" → "a_b_c") matching the
4936// scheme in scripts/gen_repr_mismatch_fixtures.py.
4937static std::string slugify_label(const std::string& label) {
4938 std::string out = label;
4939 for (char& ch : out) {
4940 if (ch == '.') ch = '_';
4941 }
4942 return out;
4943}
4944
4945// Load a captured pandas-generated expected output file. The file is written
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {