Dataframe vlookup用于另一个数据帧中的日期

问题描述 投票:1回答:1

我有一个数据框(df),其中索引是日期

              Alpha  Bravo
1997-01-02    21.14  699.25
1997-01-03    31.14  799.25
1997-01-06    41.14  899.25
1997-01-07    51.14  999.25
1997-01-08    61.14  199.25

我有另一个数据帧(df2),其中索引是数字

    Expire
0   1997-01-02
1   1997-01-07

我喜欢拥有所需的数据帧(df3)

              Alpha  Bravo   Expire
1997-01-02    21.14  699.25  1
1997-01-03    31.14  799.25  0
1997-01-06    41.14  899.25  0
1997-01-07    51.14  999.25  1
1997-01-08    61.14  199.25  0

请问有人可以建议我吗?

python pandas dataframe
1个回答
1
投票

这是一种方式:

df3['Expire'] = df3.index.isin(set(df2['Expire']))
© www.soinside.com 2019 - 2024. All rights reserved.