I have a dictionary that I would like to map onto a current dataframe and create a new column. I have keys in a tuple, which map onto two different columns in my dataframe.
dct = {('County', 'State'):'CountyType'}
df = pd.DataFrame(data=['County','State'])
I would like to create a new column, CountyType, using dict to map onto the two columns in df. However, doing the following gives me an error. How else could this be done?
df['CountyType'] = (list(zip(df.County,df.State)))
df = df.replace({'CountyType': county_type_dict)
dict, it overrides a builtin nameyourdict = df.set_index(['County','State'])['CountyType'].to_dict()Can read more here too: stackoverflow.com/questions/42276588/…