vaexio / vaex

Out-of-Core hybrid Apache Arrow/NumPy DataFrame for Python, ML, visualization and exploration of big tabular data at a billion rows per second 🚀
https://vaex.io
MIT License
8.23k stars 590 forks source link

Cant use df.evaluate with a condition to replace element with a list? #2333

Open VLouis9999 opened 1 year ago

VLouis9999 commented 1 year ago

For example, if i had a dataframe where column 3 had different sizes of lists

Column_1 Column 2 Column 3 1 a [1,2] 2 b [1,2,3] 3 c [1,2,3,4]

replace_list = [4,5,6,7] condition = (df.Column_1 == 2) if i wanted to use for example df[Column 3'] = df.evaluate(f"{replace_list} {condition}") It would say that replace_list needs to be of type str but even putting df[Column 3'] = df.evaluate(f"{str(replace_list)} {condition}") doesnt give out an answer.

Is there a solution to this? I ve tried putting the lists in column 3 as dtype object as well but it hasnt worked. The only solution so far for me has been to make a for loop but i dont know if it is very optimal eg: new_col = df.Column_3.values for i in len(df): if df.Column_1.values[i] == 2: new_col[i] = [replace_list]

df.[Column_3] = new_col