0

I have two dataframes with two columns each - 'MeetingId' and 'TAB'. The first dataframe is the full table, but it has some errors in the 'TAB' column. The second dataframe has the solutions to the errors. I would like to replace the 'TAB' column of the first dataframe with the 'TAB' column of the second datafrmae if the 'MeetingId's match up.

Example of table:

MeetingId    TAB
123          TRUE
124          FALSE

Code:

df1 = meetingdf1
df1.set_index("MeetingId")
df2 = meetingdf2
df2.set_index("MeetingId")
df1.update(df2)
print(df1)

1 Answer 1

2
df['TAB'] = df.apply(lambda x: df2[df2['MeetingId'] == x['MeetingId']]['TAB'].values[0], axis=1)

OR

df.loc[df['MeetingId'].isin(df2['MeetingId']), 'TAB'] = df2['TAB']

Example:

> df

   MeetingId    TAB
0        123   True
1        124  False

> df2

   MeetingId    TAB
0        123  False
1        124   True
2        125  False

Output after running code above:

> df

   MeetingId    TAB
0        123  False
1        124   True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.