Hi,
I want to replace values in one column according to values in another.
So for example I have the dataframe:
index: {0, 1, 2, 3, 4, 5, 6, 7}
int_col: { 1, 2, 3, 50, 6, 7, 8, 30}
int_col_2: { 5,5,5,5,5,5,5,5}
And I want to replace int_col_2 values with 0 or 1, if the corresponding value at int_col is odd or even
So my desired output would be:
index: {0, 1, 2, 3, 4, 5, 6, 7}
int_col: { 1, 2, 3, 50, 6, 7, 8, 30}
int_col_2: { 0, 1, 0, 1, 1, 0, 1, 1}
Is this possible to achieve using the replace function using functors? I ask because it seems as though you can only pass one column for input which is the same one affected by the functor e.g.
struct ReplaceFunctor {
bool operator() (const unsigned int& idx, int& value) {
value *= 5;
return (true);
}
size_t count{ 0 };
};
ReplaceFunctor functor;
dataframe.replace<int, ReplaceFunctor>("int_col", functor);
However to perform my task my ReplaceFunctor will have to look something like this:
struct ReplaceFunctor {
bool operator() (const unsigned int& idx, int& value1, int& value2) {
if(value1 % 2 == 0)
value2 = 1;
else
value2 = 0;
return (true);
}
size_t count{ 0 };
};
Please let me know if there's a way to achieve this using the replace function (or any other function for that matter), or if there's an example of something like this that I missed in the docs.
Thanks
Hi,
I want to replace values in one column according to values in another.
So for example I have the dataframe:
index: {0, 1, 2, 3, 4, 5, 6, 7}
int_col: { 1, 2, 3, 50, 6, 7, 8, 30}
int_col_2: { 5,5,5,5,5,5,5,5}
And I want to replace
int_col_2values with 0 or 1, if the corresponding value atint_colis odd or evenSo my desired output would be:
index: {0, 1, 2, 3, 4, 5, 6, 7}
int_col: { 1, 2, 3, 50, 6, 7, 8, 30}
int_col_2: { 0, 1, 0, 1, 1, 0, 1, 1}
Is this possible to achieve using the replace function using functors? I ask because it seems as though you can only pass one column for input which is the same one affected by the functor e.g.
However to perform my task my ReplaceFunctor will have to look something like this:
Please let me know if there's a way to achieve this using the replace function (or any other function for that matter), or if there's an example of something like this that I missed in the docs.
Thanks