2017-10-10 1 views

Répondre

1

utilisation nth

In [599]: df.groupby('id', as_index=False).nth(-1) 
Out[599]: 
    id   timestamp 
1 1 2015-12-03 00:00:00 
4 2 2015-12-06 00:00:00 

Idéalement, max puisque vous avez besoin de la dernière date.

In [601]: df.groupby('id', as_index=False).max() 
Out[601]: 
    id   timestamp 
0 1 2015-12-03 00:00:00 
1 2 2015-12-06 00:00:00 

En outre, tail comme mentionné dans les commentaires

In [602]: df.groupby('id').tail(1) 
Out[602]: 
    id   timestamp 
1 1 2015-12-03 00:00:00 
4 2 2015-12-06 00:00:00 
+0

max() prend le maximum sur chaque colonne, correct? – kbball