I am working with the pandas library and I want to add two new columns to a dataframe df with n columns (n > 0).
These new columns result from the application of a function to one of the columns in the dataframe.
The function to apply is like:
def calculate(x):
...operate...
return z, y
One method for creating a new column for a function returning only a value is:
df['new_col']) = df['column_A'].map(a_function)
So, what I want, and tried unsuccesfully (*), is something like:
(df['new_col_zetas'], df['new_col_ys']) = df['column_A'].map(calculate)
What the best way to accomplish this could be ?
**df['column_A'].map(calculate) returns a pandas Series each item consisting of a tuple z, y. And trying to assign this to two dataframe columns produces a ValueError.*