The Title is somewhat inelegant, but I'm not sure how to better phrase it. Anyway, say I have a dataframe with two columns:
Name ZIP
Abe 22222
Beth 11111
Charlie 11111
David 22222
And I also have a dictionary:
categ_dict = {
11111 : "Local",
22222 : "Guest"
}
I want to create a third column - Category
- and populate it by comparing the content of each cell in the ZIP
column against the the key-value pairs in the dictionary. If the content of that cell matches the key of a given pair, the "Category"
cell in the same row is populated with the value of that pair. At the end, it should look like:
Name ZIP Category
Abe 22222 Guest
Beth 11111 Local
Charlie 11111 Local
David 22222 Guest
Any insight would be greatly appreciated.