0

I have a dataframe that looks like this (i've filtered it down to the important parts):

              INC_KEY               PTOCCUPATIONALINDUSTRY
96       170000016620                       Other Services
127      170000016651                       Other Services
170      170000016694                        Manufacturing
181      170000016706                         Construction
268      170000016793                       Other Services

I was also given a 'dictionary' (not a python dictionary), that looks like this:

Dictionary

My task is to convert the values in PTOCCUPATIONALINDUSTRY to the numbers that you see in the dictionary. Is there an easy way to do this? Or do I need to manually do if statements for each value?

The reason I'm looking for a shortcut is because I need to do this exact task over ~30 different columns, so it would take forever to do it manually.

1 Answers1

0

Create your dict :

map_dict = {"Finance, Insurance, and Real Estate": 1, "etc...}

Then, simply do :

df["PTOCCUPATIONALINDUSTRY"] = df["PTOCCUPATIONALINDUSTRY"].map(map_dict)
Odhian
  • 351
  • 5
  • 14