gpt4 book ai didi

python - 类型错误 : object of type 'generator' has no len()

转载 作者:行者123 更新时间:2023-12-04 03:29:01 24 4
gpt4 key购买 nike

我该如何解决这个错误:
类型错误:“生成器”类型的对象没有 len()
谢谢!

for index, row in df_result.iterrows():
if index == 0:
tempIndex = 0
else:
if row['LEADID'] == df_result.at[tempIndex, 'LEADID']:
if type(row['ID']) is str:
df_result.at[tempIndex, 'ID'] = df_result.at[tempIndex, 'ID'] + "\n" + row['ID']
if type(row['CREATEDBYID']) is str:
df_result.at[tempIndex, 'CREATEDBYID'] = df_result.at[tempIndex, 'CREATEDBYID'] + "\n" + row['CREATEDBYID']
if type(row['CREATEDDATE']) is str:
df_result.at[tempIndex, 'CREATEDDATE'] = df_result.at[tempIndex, 'CREATEDDATE'] + "\n" + row['CREATEDDATE']
if type(row['OLDVALUE']) is str:
df_result.at[tempIndex, row['FIELD'] + "_OLDVALUE"] = df_result.at[tempIndex, row['FIELD'] + "_OLDVALUE"] + "\n" + row['OLDVALUE']
if type(row['NEWVALUE']) is str:
df_result.at[tempIndex, row['FIELD'] + "_NEWVALUE"] = df_result.at[tempIndex, row['FIELD'] + "_NEWVALUE"] + "\n" + row['NEWVALUE']
else:
resultIndexArr.append(tempIndex)
tempIndex = index

if tempIndex == len(df_result.iterrows()) - 1:
resultIndexArr.append(tempIndex)

最佳答案

您不能使用 lendf.iterrows ,因为它返回一个生成器——一个一次返回一个值的对象,并且没有长度(与 Python 序列不同)。
您可以使用 len(df.index)相反,根据 this S/O answer .

关于python - 类型错误 : object of type 'generator' has no len(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67204767/

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