Q: Python DataFrame: Find duplicates in same row? I have a df with columns - section,classA,classB,classC.I'm trying to find duplicates values in a row.
df
                section       classA          classB          classC      

            0       A          paul            john             paul
            1       B          john            mark             tony
            2       C          leo             leo              leo
            3       D          tony            tony             mark
            4       E          paul
            5       F                          mark             mark

Final df
                section       classA          classB          classC        duplicate

            0       A          paul            john             paul          True
            1       B          john            mark             tony          False
            2       C          leo             leo              leo           True
            3       D          tony            tony             mark          True
            4       E          paul                                           False
            5       F                          mark             mark          True
            6       G                                                         False

I tried comparing each row, How to handle if row is empty?

A: If the empty cells are empty strings (""), you can use set():
df["duplicate"] = df.apply(
    lambda x: len(set(x[x != ""])) != len(x[x != ""]), axis=1
)

print(df)

Prints:
  section classA classB classC  duplicate
0       A   paul   john   paul       True
1       B   john   mark   tony      False
2       C    leo    leo    leo       True
3       D   tony   tony   mark       True
4       E   paul                    False
5       F   mark   mark              True
6       G                           False

