Suppose I have a dataframe that has date and ID column. This is a time series data set. So i need to generate a time series identifier for this dataframe. That is, I need to add a value corresponding to each unique set. Is there a way to do this ?
df = pd.DataFrame({'Date':[2012-01-01, 2012-01-01, 2012-01-01, 2012-01-02, 2012-01-02, 2012-01-03, 2012-01-03, 2012-01-03, 2012-01-04, 2012-01-01, 2012-01-04],
'Id':[1,2,3,4,5,6,7,8,9,10,11]})
print(df)
Output:
Date Id
2012-01-01 1
2012-01-01 2
2012-01-01 3
2012-01-02 4
2012-01-02 5
2012-01-03 6
2012-01-03 7
2012-01-03 8
2012-01-04 9
2012-01-01 10
2012-01-04 11
I need to order the dates according to its uniqueness like
Date Id TimeID
2012-01-01 1 0
2012-01-02 4 0
2012-01-03 6 0
2012-01-04 9 0
2012-01-01 2 1
2012-01-02 5 1
2012-01-03 7 1
2012-01-04 11 1
2012-01-01 3 2
2012-01-03 8 2
2012-01-01 10 3