Create multiple columns from multiple return value of lambda function in python DataFrame

后端 未结 3 1473
萌比男神i
萌比男神i 2021-01-22 17:54

Att, I want to create multiple columns from lambda function\'s multiple return values in python DataFrame.

Similar with the last line of my demo code.

Is there

3条回答
  •  北海茫月
    2021-01-22 18:25

    An alternative to using pd.Series is to turn the output into a list. You can then assign the new columns as:

    df[['slope', 'R2']] = pd.DataFrame(df.apply(lambda x: f_polyfit(x)).tolist(), 
    index=df.index)
    

提交回复
热议问题