Python 数据帧合并方向参数问题

Python 数据帧合并方向参数问题,python,pandas,Python,Pandas,我有两个数据帧,我正在使用marge_asof合并它们(条件:来自DOY installed的值必须在DOY installed和DOY removed列创建的范围内),因此我得到: 但是,接收器类型列有一个问题。有时Receiver type在同一天发生变化,并且merge\u asof创建了错误的接收器类型的行(我认为这是由于方向参数造成的)。我怎样才能解决这个问题 代码如下: df1 = pd.DataFrame([['ABMF', 'ASTECH', 'GPS', '2008-07-1

我有两个数据帧,我正在使用
marge_asof
合并它们(条件:来自
DOY installed
的值必须在
DOY installed
DOY removed
列创建的范围内),因此我得到:

但是,
接收器类型
列有一个问题。有时
Receiver type
在同一天发生变化,并且
merge\u asof
创建了错误的
接收器类型的行(我认为这是由于
方向
参数造成的)。我怎样才能解决这个问题

代码如下:

df1 = pd.DataFrame([['ABMF', 'ASTECH', 'GPS', '2008-07-15', '2009-10-15', 2008.20, 2009.29],
                    ['ABMF', 'LEICA', 'GPS+GLO', '2009-10-15', '2011-11-15', 2009.29, 2011.32],
                    ['ABMF', 'SEPT', 'GPS+GLO', '2011-11-15', '2015-04-28', 2011.32, 2015.12],
                    ['ABMF', 'TRIMBLE', 'GPS', '2015-04-28', '2019-04-15', 2015.12, 2019.11],
                    ['ZIMM', 'ASTECH', 'GPS', '1993-05-01', '1997-08-06', 1993.12, 1997.22],
                    ['ZIMM', 'SEPT', 'GPS', '1997-08-06', '2003-08-12', 1997.22, 2003.22],
                    ['ZIMM', 'TRIMBLE', 'GPS', '2003-08-12', '2015-04-27', 2003.22, 2015.15]],
                    columns=['Station ID','Reciever type','Sattelite system','Date installed', 
                    'Date removed','DOY installed','DOY removed'])
df1.set_index(['Station ID','Reciever type'], inplace=True)

df2 = pd.DataFrame([['ABMF', 'C1P', 'C2P', 2015.09, 2015.09, -1.25, 0.15],
                    ['ABMF', 'C2W', 'C2X', 2015.14, 2015.14, -1.1, 0.1],
                    ['ABMF', 'C2C', 'C2P', 2015.14, 2015.14, -1.115, 0.123],
                    ['ABMF', 'C2W', 'C2X', 2015.22, 2015.22, -1.23, 0.12],
                    ['ABMF', 'C2W', 'C2X', 2015.42, 2015.42, -1.7, 0.124],
                    ['ZIMM', 'C2W', 'C2X', 2015.10, 2015.10, -1.21, 0.11],
                    ['ZIMM', 'C2W', 'C2X', 2015.12, 2015.12, -1.14, 0.11],
                    ['ZIMM', 'C2W', 'C2X', 2015.14, 2015.14, -1.41, 0.31]],
                    columns=['Station ID','OBS1','OBS2','Bias start','Bias end','Value','Std'])
df2.set_index('Station ID', inplace=True)

df = (pd.merge_asof(
                df2.reset_index().sort_values(by='Bias start'),
                df1.reset_index().sort_values(by='DOY installed'),
                by='Station ID',
                left_on='Bias start', right_on='DOY installed',
                direction='backward'
                )
            [['Station ID'] + df2.columns.tolist() + ['Reciever type']]
            .sort_values(by=['Station ID', 'Bias start'])
        )
df.dropna(inplace=True)
df
这是所需的输出(第2行和第3行不同):