Last active
May 9, 2021 08:53
-
-
Save UweZiegenhagen/5381ca83b0dff2eb81eb26cf249ad372 to your computer and use it in GitHub Desktop.
Medium-20210509-3.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # column names for the comparison column | |
| check_colnames= [s + '_c' for s in columnnames1] | |
| # add suffixes to distinguish between actual and expected in the merger | |
| file1 = file1.add_suffix('_e') # expected | |
| file2 = file2.add_suffix('_t') # actual, true result | |
| # merge them using the given key, use outer join | |
| comparison = pd.merge(file1,file2, how='outer', | |
| left_on=['Key_e'], | |
| right_on=['Key_t']) | |
| # create the columnwise comparison | |
| for col in columnnames1: | |
| comparison[(col + '_c')] = comparison[(col + '_t')] == comparison[(col + '_e')] | |
| # reorder the columns | |
| comparison=comparison.reindex(sorted(comparison.columns),axis=1) | |
| # save the result as Excel file | |
| comparison.to_excel('result.xlsx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment