![](/img/trans.png)
[英]TypeError: object of type 'int' has no len() in python (Password Generator)
[英]TypeError: object of type 'generator' has no len()
我该如何解决这个错误: TypeError: object of type 'generator' has no 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)
您不能在df.iterrows
上使用len
,因为它返回一个生成器 - 一个 object 一次返回一个值,并且没有长度(与 Python 序列不同)。
根据此 S/O answer ,您可以改用len(df.index)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.