pandas delete repeated rows code example

Example 1: remove duplicate row in df

df = df.drop_duplicates()

Example 2: pandas remove repeated index

df[~df.index.duplicated()]

Example 3: df remove duplicate rows

df = df.drop_duplicates()
p

Example 4: pandas remove repeated index

idx = pd.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'])
idx.drop_duplicates(keep='first')
Index(['lama', 'cow', 'beetle', 'hippo'], dtype='object')
idx.drop_duplicates(keep='last')
Index(['cow', 'beetle','lamb', 'hippo'], dtype='object')
idx.drop_duplicates(keep='False')
Index(['cow', 'beetle','hippo'], dtype='object')