Skip to content
Advertisement

Pandas: Find difference in rows with same index in any column

Sample dataframe:

JavaScript

If you see here, the rows with common index have atleast one difference amongst them.

For ex:

Rows with index 0, have difference in column_name.

Rows with index 5, have difference in max_length.

Rows with index 6, have differences in both data_type and default.

Rows with index 8, have difference in data_type.

Expected Output:

JavaScript

This is part of a bigger problem. I’ve kind of solved it till here. Not sure how to proceed further. Any ideas?

Advertisement

Answer

Here is solution similar like @Riccardo Bucco solution with Series.nunique and because always 2 values per groups output is converting to list only:

JavaScript

Solution with always 2 rows per groups index values:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement