Skip to content

Instantly share code, notes, and snippets.

@philMarius
Created October 30, 2019 12:11
Show Gist options
  • Save philMarius/d254ebdc53c894a09153fc36cd63ab7d to your computer and use it in GitHub Desktop.
Save philMarius/d254ebdc53c894a09153fc36cd63ab7d to your computer and use it in GitHub Desktop.
Comparing values between two different dataframe
def equal_dataframes(self, a_df, b_df, columns):
"""Equality check between dataframe values, first selects relevant columns, then sorts, then compares values."""
# NOTE fillna is used to eliminate NaNs as NaN != NaN
# https://stackoverflow.com/a/23666623/2126910
return (a_df[columns].sort_values(list(columns)).fillna(0).values ==
b_df[columns].sort_values(list(columns)).fillna(0).values).all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment