pandas apply output multiple columns

Solutions on MaxInterview for pandas apply output multiple columns by the best coders in the world

showing results for - "pandas apply output multiple columns"
Marlene
03 Sep 2017
1df = pd.DataFrame(np.random.randint(0,10,(10,2)), columns=["random", "a"])
2df[["sq_a","cube_a"]] = df.apply(lambda x: [x.a**2, x.a**3], axis=1, result_type="expand")
Valeria
31 Feb 2019
1>>> appiled_df = df.apply(lambda row: fn(row.text), axis='columns', result_type='expand')
2>>> df = pd.concat([df, appiled_df], axis='columns')
3