hosseinmoein / DataFrame

C++ DataFrame for statistical, Financial, and ML analysis -- in modern C++ using native types and contiguous memory storage
https://hosseinmoein.github.io/DataFrame/
BSD 3-Clause "New" or "Revised" License
2.53k stars 313 forks source link

load_column from single_act_visit.get_result() #273

Closed arjen-Lee1993 closed 11 months ago

arjen-Lee1993 commented 11 months ago

hi guys. my df contains "index" and "value(double)" column, i want to do normalization to the "value" column.i follow the guide from (https://htmlpreview.github.io/?https://github.com/hosseinmoein/DataFrame/blob/master/docs/HTML/NormalizeVisitor.html)

StandardizeVisitor<double, std::string, 64>   stand_v;
auto result = df.single_act_visit<double>("value", stand_v).get_result();

then how to load result back to "value" column i use df.load_column("value", std::move(result)); but it cause err, the type of result is std::vector<double, hmdf::AlignedAllocator<double, 64UL>> but load_column function may not support?

hosseinmoein commented 11 months ago

What error do you get? Alternatively you can do

df.get_column<double>("value") = std::move(result);

or you can use load_result_as_column().

arjen-Lee1993 commented 11 months ago

What error do you get? Alternatively you can do

df.get_column<double>("value") = std::move(result);

or you can use load_result_as_column(). @hosseinmoein Thanks for your reply! i tried but still get errors. my whole codes here:


using namespace hmdf;
using StrDataFrame = StdDataFrame<std::string>;
StrDataFrame df;
std::vector<std::string> ss = {"1", "2", "3", "4", "5"};
std::vector<double> dd = {-1, -0.4, -0.3, 0, -0.8};
df.load_index(StrDataFrame::IndexVecType{ss});
df.load_column("value", dd);
StandardizeVisitor<double, std::string, 64> stand_v;
auto result = df.single_act_visit<double>("value", stand_v).get_result();
df.get_column<double>("value") = std::move(result);

errs here:
no match for ‘operator=’ (operand types are ‘hmdf::DataFrame<std::__cxx11::basic_string<char>, hmdf::HeteroVector<0> >::ColumnVecType<double>’ {aka ‘std::vector<double, std::allocator<double> >’} and ‘std::remove_reference<std::vector<double, hmdf::AlignedAllocator<double, 64> >&>::type’ {aka ‘std::vector<double, hmdf::AlignedAllocator<double, 64> >’})

my dataframe version is v2.2.0, installed by conan
hosseinmoein commented 11 months ago

Ok, the reason is that your vectors are two different types. You declared your visitor to allocate memory on 64 byte boundary, whereas you declared your DataFrame to allocate memory on default boundaries.

Change your visitor declaration to

    StandardizeVisitor<double, std::string>  stand_v;