I have a dataframe:
import pandas as pd
d = {'user': ['bob','alice','bob'], 'item':
['apple','coconut','pear']}
df = pd.DataFrame(data=d)
user item
0 bob apple
1 alice coconut
2 bob pear
My goal is to map each string in each column to an increasing ID (start from 0) as
user item
0 0 0
1 1 1
2 0 2
For example, for column user, the [bob, alice] will map to [0,1]. The goal is to save memory for dataframe.
Moreover, is it possible to specify the column to map? For example, only mapping the user column. Thanks