DekGenius.com
PYTHON
Remove duplicates with pandas
import pandas as pd
# Drop all duplicates in the DataFrame
df = df.drop_duplicates()
# Drop all duplicates in a specific column of the DataFrame
df = df.drop_duplicates(subset = "column")
# Drop all duplicate pairs in DataFrame
df = df.drop_duplicates(subset = ["column", "column2"])
# Display DataFrame
print(df)
pandas remove repeated index
df[~df.index.duplicated()]
remove duplicate row in df
df = df.drop_duplicates()
pandas drop duplicates from column
data = data.drop_duplicates(subset=['City'], keep='first')
drop duplicate index pandas
df3 = df3[~df3.index.duplicated(keep='first')]
remove duplicates in dataframe by index python
# Remove by index
df = df[df.index.duplicated(keep='first')]
# Other methods to remove duplicates
import pandas as pd
df = df.drop_duplicates()
df = df.drop_duplicates(subset = "column")
df = df.drop_duplicates(subset = ["column", "column2"])
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')
pd df drop duplicates
df.drop_duplicates(subset=['brand', 'style'], keep='last')
df index drop duplicates
df3 = df3[~df3.index.duplicated(keep='first')]
drop duplicates data frame pandas python
df.drop_duplicates(keep=False, inplace=True)
drop duplicates columns pandas
df.loc[:,~df.columns.duplicated()]
pandas remove duplicates columns
df = df.loc[:,~df.columns.duplicated()].copy()
# https://stackoverflow.com/questions/14984119/python-pandas-remove-duplicate-columns
pandas remove duplicates
© 2022 Copyright:
DekGenius.com