I've been given a dataframe df and a function foo(int x) that returns a Series. I'd like to join df with the result of foo() for each row using a vectorized operation.
For example, given the following dataframe, I call foo() on the values of column col_1
| col_1 | col_2 | col_3 |
|---|---|---|
| 1 | 1 | 'a' |
| 12 | 2 | 'b' |
| 13 | 3 | 'd' |
| 4 | 4 | 'c' |
If we assume
foo(1) = Series('col4': 0, 'col5': 2)foo(12) = Series('col4': 1, 'col5': 3)foo(13) = Series('col4': 1, 'col5': 4)foo(4) = Series('col4': 0, 'col5': 5)
then the output should be
| col_1 | col_2 | col_3 | col4 | col5 |
|---|---|---|---|---|
| 1 | 1 | 'a' | 0 | 2 |
| 12 | 2 | 'b' | 1 | 3 |
| 13 | 3 | 'd' | 1 | 4 |
| 4 | 4 | 'c' | 0 | 5 |