I'm trying to convert a string column in a dataframe to int. The strings should be replaced with an integer as a key value.
Data:
user_id site_id
100 url1.com
100 url2.com
100 url1.com
101 url2.com
101 url2.com
101 url2.com
Wanted output:
user_id site_id
100 1
100 2
100 1
101 2
101 2
101 2
I tried to get all unique urls with:
names = pd.unique(df.site_id.ravel())
urls = pd.Series(np.arange(len(names)), names)
and then
df["site_id"] = df.applymapp(urls.get)