gpt4 book ai didi

python - 如何计算 pandas 中行的 apply 函数的迭代次数

转载 作者:行者123 更新时间:2023-12-02 20:12:45 25 4
gpt4 key购买 nike

如果我使用 apply 将函数循环到 pandas 数据框中的每一行,例如:

def my_function():
return "True"


df['Result'] = df.apply(lambda row: my_function(row), axis = 1)

如何计算迭代来跟踪进度

最佳答案

我想出了一个解决方法,如果您使用数据框,那么添加一个像这样的计数器

input_df['counter']=0

for i,row in input_df.iterrows():
input_df['counter'][i]= i+1

您的申请声明:-

input_df.apply(YourFunction,axis=1)

您的调用功能:-

def YourFunction(row):
print(row['counter'])

关于python - 如何计算 pandas 中行的 apply 函数的迭代次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53202328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com