For this question i have found this example:
df = pd.DataFrame([[i] for i in range(5)], columns=['num'])
def powers(x):
return x, x**2, x**3, x**4, x**5, x**6
df['p1'], df['p2'], df['p3'], df['p4'], df['p5'], df['p6'] = zip(*df['num'].apply(powers))
df
i changed the map()
function to apply()
function, it worked the same.
as you see we have passed a series for the apply()
function: zip(*df['num'].apply(powers))
.
This question's answer is good, But in my case of study i want to pass a dataFrame to the apply()
function as: zip(*df[['num']].apply(powers))
by adding double*double brackets df[['num']]
, but i got the following error: ValueError: not enough values to unpack (expected 6, got 3)
.
i didn't understand where the mistake is, can you help me please?