Comparing Pandas Dataframe Rows & Dropping rows with overlapping dates

后端 未结 1 638
执笔经年
执笔经年 2021-01-12 09:40

I have a dataframe filled with trades taken from a trading strategy. The logic in the trading strategy needs to be updated to ensure that trade isn\'t taken if the strategy

相关标签:
1条回答
  • 2021-01-12 09:53

    You should use some kind of boolean mask to do this kind of operation.

    One way is to create a dummy column for the next trade:

    df['EntryNextTrade'] = df['EntryDate'].shift()
    

    Use this to create the mask:

    msk = df['EntryNextTrade'] > df'[ExitDate']
    

    And use loc to look at the subDataFrame where msk is True, and only the specified columns:

    df.loc[msk, ['EntryDate', 'ExitDate']]
    
    0 讨论(0)
提交回复
热议问题