Iterate over rows/columns and extract values to a different dataframe

Viewed 37

df

enter image description here

df1

enter image description here

dfsum

enter image description here

using df-column'code', i want to reference to df1 and return column 'title' & 'cu' values to dfsum

1 Answers

if both df have the same size the you can iterate just like a regular matrix

# go through the rows
for row in range(total_rows):
    # go through the columns
    for column in range(total_columns):
        #make the condition if they match
        if df[row][column] == df1[row][column]:
            # now just assign the value from df1 to df
            df[row][column] = df1[row][column]

i hope this solves your issue :)

Related