Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save afr-dt/8d5e4656dd53abc15a6a221f1736c00e to your computer and use it in GitHub Desktop.
Save afr-dt/8d5e4656dd53abc15a6a221f1736c00e to your computer and use it in GitHub Desktop.

Revisions

  1. @toddbirchard toddbirchard created this gist Oct 20, 2019.
    11 changes: 11 additions & 0 deletions pandas_dataframe_difference.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    def dataframe_difference(df1, df2, which=None):
    """Find rows which are different."""
    comparison_df = df1.merge(df2,
    indicator=True,
    how='outer')
    if which is None:
    diff_df = comparison_df[comparison_df['_merge'] != 'both']
    else:
    diff_df = comparison_df[comparison_df['_merge'] == which]
    diff_df.to_csv('data/diff.csv')
    return diff_df