Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get duplicate and remove but keep last in python df

drop_duplicates(self, subset=None, keep="last", inplace=False)
Comment

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 :: short if python 
Python :: sha256 decrypt python 
Python :: not equal to in django filter 
Python :: generate random integers 
Python :: python strptime() 
Python :: add column to df from another df 
Python :: for python 
Python :: check for double character in a string python 
Python :: connect snowflake with python 
Python :: python icon on task bar 
Python :: rasperry pi camera 
Python :: how to bold in colorama 
Python :: how to enter a int in python 
Python :: enumerate from 1 python 
Python :: python powerpoint 
Python :: add to a list python 
Python :: merge all mp4 video files into one file python 
Python :: check if something is nan python 
Python :: remove duplicates from tuple python 
Python :: how to create a loading in pyqt5 
Python :: selenium chrome options suppress warnings python 
Python :: taking array input in python 
Python :: python logging 
Python :: read and write to file python 
Python :: get random number positive or negative python 
Python :: find frequency of numbers in list python 
Python :: print whole list python 
Python :: update nested dictionary python 
Python :: itertools .cycle() 
Python :: download image from url python requests 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =