Filter rows if the records are same across rows using pandas

Question:

Using Pandas, I am trying to filter a dataframe based on the below condition.

df = pd.DataFrame({'col1': ["A", "B", "A", "C", "B", "B"],
                   'col2': ["B", "B", "B", "C", "A","A"],
                   'col3': ["C", "B", "C", "C", "A", "A"],
                   'col4': ["D", "B", "D", "C", "B", "B"]})

df

     col1   col2    col3    col4
    0 A      B       C       D
    1 B      B       B       B
    2 A      B       C       D
    3 C      C       C       C
    4 B      A       A       B
    5 B      A       A       B

I am trying to filter the rows which contains the same record. In the above dataframe row 0 and row 2(A B C D) and row 4 and 5(B A A B) are same. Below is my expected output. Could someone help to achieve this.

 col1   col2    col3    col4
0 A      B       C       D
1 B      A       A       B
Asked By: Ajees Basha

||

Answers:

You can use pandas.DataFrame.duplicated :

df[df.duplicated()].reset_index(drop=True)

enter image description here

Answered By: L'Artiste