9951 explained code solutions for 126 technologies


python-pandasHow to drop duplicates from dataframe and keep last found


import pandas as pd

df = pd.DataFrame({
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'ip5'],
  'Price': [204,   304,   404,   405,   204  ]
})

df = df.drop_duplicates(keep='last')ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.drop_duplicates(

drops given dataframe duplicates (by default, find duplicates based on all columns values)

keep='last'

will keep last found duplicate instead of first