Evantaka
Evantaka

Reputation: 5

Get max values for each index

I have a dataframe like this

Id     timestamp   
W-001  2022-10-15T17:54:47
W-001  2022-10-15T17:55:20
W-001  2022-10-15T17:55:21
W-002  2022-11-11T15:12:43
W-002  2022-11-11T15:12:50
W-002  2022-11-11T15:12:55
W-002  2022-11-11T15:12:57
W-003  2022-11-18T09:35:12
W-003  2022-11-18T09:35:13
W-003  2022-11-18T09:35:17
W-003  2022-11-18T09:35:23

I want result to be like this, select ID with the latest timestamp

Id     timestamp   
W-001  2022-10-15T17:55:21
W-002  2022-11-11T15:12:57
W-003  2022-11-18T09:35:23

Upvotes: 0

Views: 67

Answers (1)

Isaac Rene
Isaac Rene

Reputation: 396

You can try:

df.groupby(by=['Id']).max().reset_index()

Upvotes: 1

Related Questions