将pandas函数应用于列以创建多个新列?

将pandas函数应用于列以创建多个新列?,第1张

将pandas函数应用于列以创建多个新列?

基于user1827356的答案,您可以使用

df.merge
以下命令一口气完成分配:

df.merge(df.textcol.apply(lambda s: pd.Series({'feature1':s+1, 'feature2':s-1})),     left_index=True, right_index=True)    textcol  feature1  feature20  0.772692  1.772692 -0.2273081  0.857210  1.857210 -0.1427902  0.065639  1.065639 -0.9343613  0.819160  1.819160 -0.1808404  0.088212  1.088212 -0.911788

编辑: 请注意巨大的内存消耗和低速:https : //ys-l.github.io/posts/2015/08/28/how-not-to-use-
pandas-apply/



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5655611.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存