We can use the DataFrame.drop_duplicates() function to remove duplicate rows from a DataFrame using the pandas Python library. Let’s say we have the following DataFrame:
0 1 2
0 1 2 3
1 4 5 6
2 7 8 9
3 1 2 3
4 10 11 12
Here, row 0 and row 3 are duplicates. So, we want to remove the duplicate row. We can use the following Python code to do the same:
import pandas
list1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3], [10, 11, 12]]
df = pandas.DataFrame(list1)
print("df: \n", df)
df2 = df.drop_duplicates(keep="first", inplace=False, ignore_index=False)
print("df2: \n", df2)
The output will be:








































0 Comments