1 Upvote
How to Find Differences In Dataframe Rows
In this code snippet we compare two rows in the same dataframe or different dataframes with the same columns. Where there are differences the column name and the column values from each row are printed for each differing column.
columns_to_compare = ['a', 'b', 'c'] # Compare rows in the same dataframe: for column in columns_to_compare: if df[column][0] != df[column][1]: print(column) print(df[column][0]) print(df[column][1]) # Compare rows in different dataframes: for column in columns_to_compare: if df1[column][0] != df2[column][0]: print(column) print(df1[column][0]) print(df2[column][0])
By detro - Last Updated June 4, 2022, 10:15 p.m.
COMMENTS
RELATED SNIPPETS
5
3
3
Labelled Correlation Heatmap Using Seaborn
Python
Visualisation & EDA
3
3
How to Return the Most Frequent Bigrams from Text Using NLTK
Python
Visualisation & EDA
2
2
1
1
Creating a Frequency Table from a Dataframe Column
Python
Visualisation & EDA
1
Find Snippets by Language
Find Snippets by Use