I have a column in my dataframe with barcodes and created a dictionary to map barcodes to item ids.
I am creating a new column:
df['item_id'] = df['bar_code']
A dictionary (out of a second dataframe - imdb -)
keys = (int(i) for i in imdb['bar_code'])
values = (int(i) for i in imdb['item_id'])
map_barcode = dict(zip(keys, values))
map_barcode (first 5 e.g.)
{0: 1000159, 9000000017515: 11, 7792690324216: 16, 7792690324209: 20, 70942503334: 33}
And then mapping the item id with the dict
df = df.replace({'item_id':map_barcode})
Here I am hoping to obtain the item ids in the column
(Going back to the dict examples:)
df['item_id'][0] = 1000159
df['item_id'][1] = 11
df['item_id'][2] = 16
df['item_id'][3] = 20
df['item_id'][4] = 33
But end up getting this error:
Cannot compare types 'ndarray(dtype=int64)' and 'int64'
I tried to change the type of the dictionary to np.int64
keys = (np.int64(i) for i in imdb['bar_code'])
values = (np.int64(i) for i in imdb['item_id'])
map_barcode = dict(zip(keys, values))
But got the same error.
Is there anything I am missing here?