I want nearly the same as answered here for pandas
- but want to run it in vaex
.
As vaex
does lazy copy, for me it would be okay, to save (my two) columns of str.split
into the vaex-df. But there is nothing like expand=True
.
Asked
Active
Viewed 1,158 times
0

Bastian Ebeling
- 1,138
- 11
- 38
1 Answers
1
To do this with vaex 4.0.0 you can't retrieve a token by using the slice directly, you have to use the slice inside the apply
method.
Here is the example adapted for vaex:
import pandas as pd
import vaex
df = pd.DataFrame({'ticker' : ['spx 5/25/2001 p500', 'spx 5/25/2001 p600', 'spx 5/25/2001 p700']})
df_vaex = vaex.from_pandas(df)
df_vaex["ticker"].str.split(" ").apply(lambda x: x[-1])
And it gives the expected output:
Expression = lambda_function(str_split(ticker, ' '))
Length: 3 dtype: string (expression)
------------------------------------
0 p500
1 p600
2 p700

M. Perier--Dulhoste
- 884
- 6
- 8