Answers for "delete duplicates in pandas"

6

delete the duplicates in python

mylist = ["a", "b", "a", "c", "c"]
mylist = list(dict.fromkeys(mylist))

  print(mylist)
Posted by: Guest on May-19-2020
0

delete duplicates in pandas

import pandas as pd

# Create a sample DataFrame with duplicate rows
df = pd.DataFrame({'A': ['a', 'a', 'b', 'c', 'c'], 
                   'B': [1, 1, 2, 3, 3], 
                   'C': [4, 5, 6, 7, 8]})

# Print the DataFrame
print(df)

# Remove duplicate rows
df = df.drop_duplicates()

# Print the result
print(df)
Posted by: codethreads dev on December-28-2022

Python Answers by Framework

Browse Popular Code Answers by Language