首页 > 解决方案 > 根据单独的值与不同数据框的关系更改数据框中的值

问题描述

我有一个看起来像这样的df:

FiscalPeriod , VendorNum, Bool_1, Bool_2, Bool_3
      1      ,   0001   ,   False, False , True
      2      ,   0002   ,   True, False , True

然后我的 bool_df 看起来像这样:

VendorNum    , Bools    ,      1,      2,    3
   0001      ,   Bool_1 ,   True, False , True
   0002      ,   Bool_1 ,   True, False , True
   0001      ,   Bool_2 ,   True, False , True
   0001      ,   Bool_3 ,   False, False , True

我想写一些东西来改变第一个 df 中相应的 Bool 列,以便它们只在会计期间列有一个数字,其相应的 bool_df 列对于该 bool 为 true 时才会读取,因此结果如下。

    FiscalPeriod , VendorNum, Bool_1, Bool_2, Bool_3
      1      ,   0001   ,   **True,**  **True**  , **False**
      2      ,   0002   ,   **False**, False , True
     

我已经用粗体标出了要进行更改的地方。

标签: pythonpandasdataframe

解决方案


推荐阅读