Q:

Assign value to column based on lookup table using pandas

I've the following matrix:
destinations = ["DC","NY","SF","AL"]

workinDays = [[3, 5, 7, 7], 
                [5, 5, 7, 7],
                [7, 7, 7, 7],
                [7, 7, 7, 7]]

working_days_df = pd.DataFrame(data=workinDays, columns=destinations,
                 index=destinations).astype(str) + " working days"

Based on the above matrix (When you run the above code you'll get a matrix in a dataset form) I want to assign value to another dataset other_df which has upto 100 rows:
dest1   dest2
DC      DC
NY      AL
...

So I want to add a new column which reads the correct value from the matrix above. For example in row 2 dest1 is NY ad dest2 is AL. So based on the matrix it's value should be 7. How can I do that?

A:

IIUC, you can perform a lookup:
df_other['new'] = working_days_df.lookup(df_other['dest1'], df_other['dest2'])

Here, working_days_df is your matrix DataFrame, while df_other is the one you'd like to lookup values for.

