Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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")
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #apply #output #multiple #columns
ADD COMMENT
Topic
Name
4+1 =