So I created a dictionary with every state abbreviation and the keys are "East", "Central", and "West"
states_dict = {
'West': ["CA","OR","WA","NV","ID","UT","AZ","MT","AK"],
'Central': ["WY","CO","NM","ND","SD","NE","KS","OK","TX","MN","IA","MO","AR","LA","WI","IL","MS"],
'East': ["MI","IN","KY","TN","AL","OH","GA","FL","SC","NC","VA","WV","DE","MD","NJ","PA","NY","CT","RI","MA","VT","NH","ME"]
}
I'm trying to figure out a way to apply this to a column of code and return the dictionary keys instead in the column. For example if it is ["CA", "FL"] I want the column to be ["West","East]. I created a for loop where i appended the keys into a new list and it wasnt the correct length so I started using .replace and that is just continually running. Here is my code.
for x in df['X20']:
for i,j in states_dict.items():
for v in j:
if x==v:
x20=df['X20'].replace(x,i)
else:
pass
x20