Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas drop duplicate keep last

df = df.sort_values('timestamp').drop_duplicates(['customer_id','var_name'], keep='last')
print (df)
   customer_id  value var_name                timestamp
0            1      1    apple  2018-03-22 00:00:00.000
3            1      1   orange  2018-03-22 08:00:00.000
2            2      4    apple  2018-03-24 08:00:00.000
4            2      3   orange  2018-03-24 08:00:00.000
Comment

pandas drop duplicates but keep most recent date

df.sort_values('DATE_CHANGED').drop_duplicates('STATION_ID',keep='last')
Comment

PREVIOUS NEXT
Code Example
Python :: concact geodataframe python 
Python :: pytorch cuda tensor in module 
Python :: change base python 
Python :: default values python 
Python :: upload file to s3 
Python :: python convert ascii to char 
Python :: Character limit python system 
Python :: remove key from dictionary 
Python :: python list input print 
Python :: pronic number program in python 
Python :: download unsplash images code 
Python :: eval function in python 
Python :: python while 
Python :: python multithreading 
Python :: make parameter optional python 
Python :: pandas to python datetime 
Python :: how to capture video in google colab with python 
Python :: staticmethod python 
Python :: Python program to find N largest elements from a list 
Python :: how to find the longest string python 
Python :: python find if strings are anagrams 
Python :: How to Add Elements To a Set using add() method in python 
Python :: pytube python 
Python :: how to convert response to beautifulsoup object 
Python :: pafy doc 
Python :: uppercase python 
Python :: files python 
Python :: python get text of QLineEdit 
Python :: python compare each item of one list 
Python :: pip change python version 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =