[英]Pandas: how to apply a transformation to each row?
最初我有一行,我想在一些非平凡的算法之后为每一行设置一些新的列。
我可以这样做:
for index, row in df.iterrows():
df.loc[df.index == index, 'NEW_COL'] = ...
但它很笨拙。 有没有办法将lambda行 - >行并将其应用于数据帧?
我想你想要的东西:
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)
如果您想要更具体的内容,请在帖子中提供更多详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.