From 0a7a38dbf1f1c1fc1c24cae33b7ffc2d83bab895 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Fri, 21 Feb 2020 20:13:01 +0300 Subject: [PATCH] Add dataframe_difference() helper function --- freqtrade/data/btanalysis.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index c28e462ba..6239bec0b 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -188,3 +188,20 @@ def create_cum_profit(df: pd.DataFrame, trades: pd.DataFrame, col_name: str, # FFill to get continuous df[col_name] = df[col_name].ffill() return df + + +def dataframe_difference(df1: pd.DataFrame, df2: pd.DataFrame, which=None): + """ + Find rows which are different between two DataFrames. + Taken with small adaptation from: + https://hackersandslackers.com/compare-rows-pandas-dataframes/ + :param which: Allows to print 'left_only', 'right_only' or 'both' rows. + """ + 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] + return diff_df