I want to search with a string in a pandas dataframe A, compare it with another dataframe B and write the value from another column of that dataframe B into the original column in dataframe A. Like:
Table_a:
| fruit | attribute |
|---|---|
| apple | red |
| banana | yellow |
| orange | orange |
Table_b:
| fruit | size | abbrev. |
|---|---|---|
| apple | large | app. |
| orange | medium | oran. |
| peach | small | pea. |
| banana | medium | ban. |
So the modified table_a shall be:
| fruit | attribute |
|---|---|
| apple | app. |
| banana | ban. |
| orange | ora. |
How can I search across two dataframes and replace with a specific column from df_b?
This has been my non-working approach so far. Can you help, pls?
table_a["attribute"] = table_a.loc[table_a["fruit"] == table_b["fruit"], table_b["attribute"]