Feb-28-2023, 02:03 PM
I'm trying to update ta row's column based on the previous row's column's value.
Like the following
Like the following
d = {'col1': ['A', 'B', 'C', 'D'], 'col2': [1, 2, 3, 4], 'col3': ['E', 'F', 'G', 'H']}
df = pd.DataFrame(data=d)
rows = df.itertuples()
prev = next(rows) # Gets first row
for row in rows: # Will start at second row
print("Current index:",row)
setattr(row, 'col3') = getattr(prev,'col1')
prev = rowThis throws the error, 'SyntaxError: cannot assign to function call'. Guess I will have to use iloc or loc?
