【发布时间】:2021-07-03 07:17:34
【问题描述】:
我有一个数据框 A,其中包含多个列,这是两个数据框合并的结果。合并后,我需要根据其他列的值更新A中答案列的值。
伪代码:
for all agreements in A :
if the length of the value in the year column in A is less than four:
update string in answer column of A without the value from year column
else:
update string in answer column of A with the value from year column
我正在尝试什么:
for row in A.itertuples() :
if len(str(A.Year)) < 4 :
row.answer = 'Status on ' + row.Name + ' is ' + row.Status
else :
row.answer = 'Status on ' + row.Name + ' ' + str(row.Year) + ' is ' + row.Status
我收到一个错误 AttributeError: can't set attribute
有什么建议吗?
【问题讨论】:
标签: python pandas dataframe loops attributeerror