I have a function that returns tuple:
def pwrs(x):
return x*x, x*x*x, x*x*x*x
I would like to apply this function to a single column dataframe named data:
+-------+
| x |
+-------+
| 1 |
| 2 |
| 3 |
| 4 |
+-------+
and get back a new dataframe with new columns based on the function return tuples:
+---+------+------+------+
| x | x^2 | x^3 | x^4 |
+---+------+------+------+
| 1 | 1 | 1 | 1 |
| 2 | 4 | 8 | 16 |
| 3 | 9 | 27 | 81 |
| 4 | 16 | 64 | 256 |
+---+------+------+------+
Got as far as iterating through the rows and applying the function:
for _, row in data.iterrows():
print(pwrs(row['x']))
Not sure how to progress from here....
np.vandermight be of use