Python Forum
How to keep last entry from duplicate entries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to keep last entry from duplicate entries
#2
One way to keep last row from filtered rows is to use .tail(n=1):

>>> import pandas as pd
>>> df = pd.DataFrame([1, 2, 1, 2, 3, 3])                                                                              
>>> df                                                                                                                 
   0
0  1
1  2
2  1
3  2
4  3
5  3
>>> df.loc[df[0] == 2].tail(n=1)                                                                                       
   0
3  2
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: How to keep last entry from duplicate entries - by perfringo - Jan-09-2020, 04:18 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020