I'm trying to create a new column designating the region of a state based on the state alpha code column. I've reviewed other questions, and tried both using .apply and using np.select as shown below. Can someone please help me fix the code, and explain the concept behind what is happening behind the scenes so I can understand how to fix this issue moving forward.
Kansas_City = ['ND', 'SD', 'NE', 'KS', 'MN', 'IA', 'MO']
Dallas = ['TX', 'OK', 'AR', 'LA', 'TN']
conditions = [df_merge['state_alpha'] in Kansas_City, df_merge['state_alpha'] in Dallas]
outputs = ['Kansas City', 'Dallas']
df_merge['Region'] = np.select(conditions, outputs, 'Other')
The other question I was trying to follow is here - pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
state_alpha Region
'MN' Kansas City
'TX' Dallas
'IA' Kansas City
'NE' Kansas City