Back to Documentations

Signature Description Parameters
template<typename ... Ts>
DataFrame<DateTime, H>
get_data_in_months(const std::vector<DT_MONTH> &months) const;
This selects the rows using the index column that happen in the specified months. It returns another DataFrame with selected data indexed by DateTime. Self is unchanged.

NOTE: The index column type must be DateTime or it won't compile
Ts: List all the types of all data columns. A type should be specified in the list only once.
months: List of specified months
template<typename ... Ts>
PtrView
get_view_in_months(const std::vector<DT_MONTH> &months);
It behaves like get_data_in_months(), but it returns a View. A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.

NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.
Ts: List all the types of all data columns. A type should be specified in the list only once.
months: List of specified months
template<typename ... Ts>
ConstPtrView
get_view_in_months(const std::vector<DT_MONTH> &months) const;
Same as above view, but it returns a const view. You can not change data in const views. But if the data is changed in the original DataFrame or through another view, it is reflected in the const view. Ts: List all the types of all data columns. A type should be specified in the list only once.
months: List of specified months
static void test_get_data_in_months()  {

    std::cout << "\nTesting get_data_in_months( ) ..." << std::endl;

    DTDataFrame df;

    try  {
        df.read("DT_Intraday.csv", io_format::csv2);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
    }

    const auto  result = df.get_view_in_months<double, long>({ DT_MONTH::JAN, DT_MONTH::NOV });

    assert(result.get_index().size() == 2101);
    assert(result.get_index()[0].date() == 19861115);
    assert(result.get_index()[100].date() == 19861117);
    assert(result.get_index()[1000].date() == 19870107);
    assert(result.get_index()[2100].date() == 19870131);
    assert(result.get_column<double>("dbl value").size() == 2101);
    assert(result.get_column<double>("dbl value")[0] == 0.5);
    assert(result.get_column<double>("dbl value")[100] == 50.5);
    assert(result.get_column<double>("dbl value")[1000] == 1198.0);
    assert(result.get_column<double>("dbl value")[2100] == 1748.0);
    assert(result.get_column<long>("lng value").size() == 2101);
    assert(result.get_column<long>("lng value")[0] == 10);
    assert(result.get_column<long>("lng value")[100] == 1010);
    assert(result.get_column<long>("lng value")[1000] == 23960);
    assert(result.get_column<long>("lng value")[2100] == 34960);
}

C++ DataFrame