-1

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

Fuzzygg
  • 9
  • 3
  • please add your input data as text (not as image). What do you mean by "if the string match", match with what? – Rabinzel Sep 14 '22 at 07:24

1 Answers1

-1

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 :)

  • df has a shape of (24,18) while df1 has (38,4). – Fuzzygg Sep 14 '22 at 07:48
  • ok, please try to explain better how the comparison its gonna be with a different size of dfs – Marcos Flores Sep 14 '22 at 07:52
  • i extract a specific str and assign to a variable called var. Now var=gg. with this, i will need to go to df1 extract the row data and pluck into df. is this infor sufficient? apologise if i am not providing what you wanted as i am still very new to this python – Fuzzygg Sep 14 '22 at 08:05
  • please edit your question and add the information we need there. With that I mean, don't post a picture with df which has no data. Create an example df and post it as text, then you show us the desired output on that specific example. Like that we can understand what your goal is. – Rabinzel Sep 14 '22 at 08:20
  • i have updated the questions but unable to copy code in text to the questions. – Fuzzygg Sep 15 '22 at 01:33