Skip to content

Update values in one table based off the values in another table. #8169

Answered by cpcloud
JRocki asked this question in Q&A
Discussion options

You must be logged in to vote

I would suggest a left outer join on ID, followed by selecting the Value column from the right side of the join:

In [32]: import pandas as pd

In [33]: from ibis.interactive import *

In [34]: df1 = pd.DataFrame({'ID': range(10), 'Value': range(10, 20)})

In [35]: df2 = pd.DataFrame({'ID': [3, 7], 'Value': [100, 200]})

In [36]:

In [36]: table1 = ibis.memtable(df1)

In [37]: table2 = ibis.memtable(df2)

In [38]: table1[["ID"]].left_join(table2, "ID").select(table1.ID, table2.Value)
Out[38]:
┏━━━━━━━┳━━━━━━━┓
┃ ID    ┃ Value ┃
┡━━━━━━━╇━━━━━━━┩
│ int64 │ int64 │
├───────┼───────┤
│     3 │   100 │
│     7 │   200 │
│     0 │  NULL │
│     1 │  NULL │
│     2 │  NULL │
│     4 │  NULL │
│ …

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by cpcloud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants