It seens that you could use pandas.factorize to solve your problem.
pandas.factorize
pandas.factorize(values, sort=False, na_sentinel=- 1, size_hint=None)
This method is useful for obtaining a numeric representation of an array when all that matters is identifying distinct values. factorize is available as both a top-level function pandas.factorize(), and as a method Series.factorize() and Index.factorize().
You can try something like this.
import pandas as pd
dates = pd.Series(['1/5/2020', '1/5/2020', '2/5/2020', '3/5/2020', '3/5/2020', '8/5/2020', '8/5/2020', '8/5/2020'])
dates_with_data = pd.DataFrame({"dates": dates, "data": dates})
(factorized_dates, categorical_dates) = dates_with_data["dates"].factorize()
dates_with_data['dates'] = factorized_dates
dates_with_data.head()
I hope this have been useful.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…