Using Vaex, I would like to make a selection of rows, modify the values of some columns on that selection and get the changes applied on the original dataframe.
I can do a selection and make changes to that selection, but how can I get them ported to the original dataframe?
df = vaex.from_pandas(pd.DataFrame({'a':[1,2], 'b':[3,4]}))
df_selected = df[df.a==1]
df_selected['b'] = df_selected.b * 0 + 5
df_selected
# a b
0 1 5
df
# a b
0 1 3
1 2 4
So far, the only solution that comes to my mind is to obtain two complementary selections, modify the one I am interested in, and then concatenate it with the other selection. Is there a more direct way of doing this?
You are probably looking for the where
method.
I think it should be something like this:
df = vaex.from_pandas(pd.DataFrame({'a':[1,2], 'b':[3,4]}))
df['c'] = df.func.where(df.a==1, df.b * 0 + 5, df.a)
The where
syntax is
where(if, then, else)
or where(condition, if condition satisfied, otherwise)
.