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

PREVIOUS NEXT
Code Example
Python :: how to find the multiples of a number in python 
Python :: python datetime to timestamp 
Python :: print fibonacci series in reverse in python 
Python :: python selenium type in input 
Python :: python ssh library 
Python :: python dividing strings by amount of letters 
Python :: python iterate over multidimensional dictionary 
Python :: list of strings to numbers python 
Python :: como deixar todas as letras maiusculas no python 
Python :: pd combine date time 
Python :: Get all columns with particular name in string 
Python :: tkinter canvas remove 
Python :: explode dictionary pandas 
Python :: python move item in list to end 
Python :: how to check which python version is installed 
Python :: python drop axis 
Python :: python voice recognition 
Python :: reset a turtle python 
Python :: generate random list of number py 
Python :: python json load file 
Python :: how to invert a list in python 
Python :: python way to unindent blocks of code 
Python :: pandas replace zero with blank 
Python :: get columns that contain null values pandas 
Python :: python type hint for a string 
Python :: tkinter hello world 
Python :: python- find multiple values in a column 
Python :: how to detect an even number in python 
Python :: drf default pagination 
Python :: python print user input 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =