Answered by : elisabeth-engering
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)
Source : https://www.datacamp.com/cheat-sheet/pandas-cheat-sheet-for-data-science-in-python | Last Update : Fri, 06 May 22
Answered by : clean-chimpanzee-x9xh2muu92w1
data = data.drop_duplicates(subset=['City'], keep='first')
Source : https://duckduckgo.com/?q=pandas+drop+duplicates+from+column&t=brave&ia=web | Last Update : Sun, 22 May 22
Answered by : juan-lpez-iglesias
{"tags":[{"tag":"p","content":"borrar duplicados pandas"},{"tag":"textarea","content":"# Below are quick example\n# keep first duplicate row\ndf2 = df.drop_duplicates()\n\n# Using DataFrame.drop_duplicates() to keep first duplicate row\ndf2 = df.drop_duplicates(keep='first')\n\n# keep last duplicate row\ndf2 = df.drop_duplicates( keep='last')\n\n# Remove all duplicate rows \ndf2 = df.drop_duplicates(keep=False)\n\n# Delete duplicate rows based on specific columns \ndf2 = df.drop_duplicates(subset=[\"Courses\", \"Fee\"], keep=False)\n\n# Drop duplicate rows in place\ndf.drop_duplicates(inplace=True)\n\n# Using DataFrame.apply() and lambda function \ndf2 = df.apply(lambda x: x.astype(str).str.lower()).drop_duplicates(subset=['Courses', 'Fee'], keep='first')","code_language":"c"}]}
Source : https://sparkbyexamples.com/pandas/pandas-drop-duplicate-rows-from-dataframe/ | Last Update : Thu, 23 Feb 23
Answered by : athul-mathew
df.drop_duplicates(keep=False, inplace=True)
Source : https://stackoverflow.com/questions/23667369/drop-all-duplicate-rows-across-multiple-columns-in-python-pandas | Last Update : Tue, 02 Aug 22
Answered by : doubtful-dormouse-uimhy2ojhi0j
{"tags":[{"tag":"textarea","content":"df3 = df3[~df3.index.duplicated(keep='first')]","code_language":"python"}]}
Source : https://stackoverflow.com/questions/13035764/remove-pandas-rows-with-duplicate-indices | Last Update : Thu, 06 Apr 23
Answered by : or-berger
df.loc[:,~df.columns.duplicated()]
Source : | Last Update : Wed, 08 Jun 22
Answered by : perfect-penguin-a1nt3r09ybl6
df = df.loc[:,~df.columns.duplicated()].copy()
# https://stackoverflow.com/questions/14984119/python-pandas-remove-duplicate-columns
Source : | Last Update : Mon, 10 Oct 22
Answered by : brave-bat-gssz4vb0pdep
{"tags":[{"tag":"textarea","content":"data.loc[data['email'].duplicated(keep=False),:]","code_language":"whatever"}]}
Source : https://openclassrooms.com/fr/courses/7410486-nettoyez-et-analysez-votre-jeu-de-donnees/7451506-nettoyez-vos-donnees-avec-python | Last Update : Sat, 18 Feb 23
Answered by : lazy-lark-jenyffc7wa94
df.drop_duplicates()
Source : | Last Update : Mon, 30 May 22