drop duplicates pandas code example
Example 1: drop duplicates pandas first column
import pandas as pd
data = pd.read_csv("employees.csv")
data.sort_values("First Name", inplace = True)
data.drop_duplicates(subset ="First Name",keep = False, inplace = True)
print(data)
Example 2: remove duplicate row in df
df = df.drop_duplicates()
Example 3: drop duplicate index pandas
df3 = df3[~df3.index.duplicated(keep='first')]
Example 4: remove duplicate columns python dataframe
df = df.loc[:,~df.columns.duplicated()]
Example 5: df remove duplicate rows
df = df.drop_duplicates()
p
Example 6: 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')