Answers for "pandas apply output multiple columns"

0

pandas apply output multiple columns

df = pd.DataFrame(np.random.randint(0,10,(10,2)), columns=["random", "a"])
df[["sq_a","cube_a"]] = df.apply(lambda x: [x.a**2, x.a**3], axis=1, result_type="expand")
Posted by: Guest on October-04-2021
0

pandas apply output multiple columns

>>> appiled_df = df.apply(lambda row: fn(row.text), axis='columns', result_type='expand')
>>> df = pd.concat([df, appiled_df], axis='columns')
Posted by: Guest on September-17-2021

Code answers related to "pandas apply output multiple columns"

Python Answers by Framework

Browse Popular Code Answers by Language