I have a large df that has this structure:
data = pd.DataFrame({'a': ['red', 'blue', 'green', 'cat', 'dog'],
'b': [1, 1, 2, 3, 3]})
I have a dict that assigns categories like so:
category_dict = {'red': ['color'],
'blue': ['color'],
'green': ['color'],
'cat': ['animal'],
'dog': ['animal']}
I want to use the dict to create another column with the categories:
data_update = pd.DataFrame({'a': ['red', 'blue', 'green', 'cat', 'dog'],
'b': [1, 1, 2, 3, 3],
'c': ['color', 'color', 'color', 'animal', 'animal']})
I thought data['c'] = category_dict[data['a']]
would give my output, but instead I get the error 'Series' objects are mutable, thus they cannot be hashed