xframe is a dataframe for C++, based on xtensor and xtl


In [ ]:
#include <string>
#include <iostream>

#include "xtl/xbasic_fixed_string.hpp"

#include "xtensor/xio.hpp"

#include "xframe/xvariable.hpp"
#include "xframe/xvariable_view.hpp"

In [ ]:
using fstring = xtl::xfixed_string<55>;

using data_type = xt::xoptional_assembly<xt::xarray<double>, xt::xarray<bool>>;
using coordinate_type = xf::xcoordinate<fstring, data_type::size_type>;

using variable_type = xf::xvariable<coordinate_type, data_type>;

Axis


In [ ]:
// Creation of an axis with `int` labels, given the size
std::cout << xf::axis(15);

In [ ]:
// `int` labels, given the start and stop
std::cout << xf::axis(5, 15);

In [ ]:
// `double` labels, given the start, stop and step
std::cout << xf::axis(0., 1., 0.1);

In [ ]:
// `char` labels, given the start and stop
std::cout << xf::axis('d', 'r', char(2));

 Variable with 2D Data


In [ ]:
data_type data1 = {{ 1., 2., 3.},
                  { 4., 5., 6.},
                  { 7., 8., 9.}};
data1(0, 2).has_value() = false;
data1(1, 0).has_value() = false;

In [ ]:
auto var1 = variable_type(
    data1,
    {
        {"abscissa", xf::axis({'a', 'c', 'd'})},
        {"ordinate", xf::axis({1, 2, 4})}
    }
);

In [ ]:
std::cout << var1.select({{"abscissa", 'a'}, {"ordinate", 1}});

In [ ]:
std::cout << var1.locate('c', 2);

In [ ]:
std::cout << var1;

In [ ]:
auto var2 = variable_type(
    data1, 
    {
        {"abscissa", xf::axis({'a', 'c', 'e'})},
        {"ordinate", xf::axis({1, 3, 4})}
    }
);

In [ ]:
variable_type res1 = var1 + var2;

In [ ]:
std::cout << res1;

 Variable with 3D data


In [ ]:
data_type data2 = {{{ 1.,  2., 3. },
                    { 4.,  5., 6. },
                    { 7.,  8., 9. }},
                   {{ 1.3, 1.5, 1.},
                    { 2., 2.3, 2.4},
                    { 3.1, 3.8, 3.}},
                   {{ 8.5, 8.2, 8.6},
                    { 7.5, 8.6, 9.7},
                    { 4.5, 4.4, 4.3}}};

In [ ]:
auto var3 = variable_type(
    data2,
    {
        {"abscissa", xf::axis({'a', 'c', 'd'})},
        {"ordinate", xf::axis({1, 2, 4})},
        {"altitude", xf::axis(3)},
    }
);

In [ ]:
std::cout << var3;

In [ ]:
variable_type res2 = var1 * var3;

In [ ]:
std::cout << res2;