且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

遍历一列并填充fucntion Pandas Dataframe Python中的行

更新时间:2023-10-04 19:27:22

如果您希望所有列+函数产生的新列,您可以这样做:

If you want all the columns + the new column which is the result of your function, you can do so:

df['result'] = calc_funct(df['x'], df['y'], df['z'])

或仅dateresult以及另一行代码:

or just date and result with this other line of code:

df = df[['date','result']]

编辑

result = []
for index, row in df.iterrows():
    result.append(row['date'])
    result.append(calc_funct(row['x'], row['y'], row['z']))
print result