最初我有一行数据,我想根据一些复杂的算法为每一行设置一些新列。 我可以这样做: for index, row in df.iterrows(): df.loc[df.index == index, 'NEW_COL'] = ... 但这样做非常笨拙。有没有一种方法来定义lambda row -> row并将其应用于数据框?
我认为你需要的是这样的东西:def func(row): row.(here you can access any column of your dataframe) return (the value in here will go to the 'NEW_COL' you are defining) df['NEW_COL'] = df.apply(func,axis=1) 如果你想要更具体的东西,请在你的帖子中提供更多细节。
df.apply(lambda row: func(row), axis=1)
吗? - EdChumdf.apply
选项在只需要一个数据列时非常简单易用。您能否给我们透露一下这个非平凡算法的提示? - Maarten Fabré