0

Let's say I have a pandas dataframe as follows

data = {'category': [1,2,1,2,1],
        'description': ['...', '...','...','...','...']}
df = pd.DataFrame(data)

Then I also have a reference dataframe

reference = {'reference': [1, 2],
             'value': ['blue', 'green']}
ref = pd.DataFrame(reference)

I'd like to create a 'category_2' variable in df that matches up with the value column in the reference data frame... How would I go about doing this in python? I know it's probably simple but I come from an R background so this is confusing to me. I also am struggling with how to phrase a question to search for this. Any advice is greatly appreciated.

Here's the final result I'm after:

final = {'category': [1,2,1,2,1],
        'description': ['...', '...','...','...','...'],
        'category_2': ['blue', 'green', 'blue', 'green', 'blue']}
final_df = pd.DataFrame(final)
tfr950
  • 362
  • 1
  • 8

0 Answers0