我遇到的问题与此帖子https://stackoverflow.com/questions/45086369/assign-unique-id-to-each-unique-value-in-group-after-pandas-groupby类似,但是,groupby的其中一列是Timestamp,它给我的输出很奇怪,如下所示:
from pandas import Timestamp
df=pd.DataFrame({'day': [Timestamp('2017-03-27'),
Timestamp('2017-03-27'),Timestamp('2017-04-01'),
Timestamp('2017-04-03'),Timestamp('2017-04-06'),
Timestamp('2017-04-07'),Timestamp('2017-04-11'),
Timestamp('2017-05-01'),Timestamp('2017-05-01')],
'act_id': ['916298883','916298883','916298883','926539428','930641527',
'930641527','930641527','966163233','966163233']})
我这样做了:
df['no_adm'] = df.groupby('act_id')['day'].transform(lambda x: pd.factorize(x)[0]+1)
它给了我
我不知道1970-01-01 00:00:00.0000000000是怎么来的并将其删除。我只希望我的数据框在no_adm列中不包含那些timestamp元素。