pandas - 根据 2 个数据帧 (df1, df2) 之间的匹配列更新一个 DF (df1) 的行
问题描述
我有两个数据框
DF1:
EmployeeID CollectiveBargainingUnit BusinessGroup ProfitCenter Eligible 1 12A A12 UGZ. 2 17A B12 MGZ. 3 18A C12 DGZ. 4 19A D12 XGZ.
DF2:
CollectiveBargainingUnit BusinessGroup ProfitCenter Eligible 12A A12 UGZ. True 17A B12 MGZ. False 18A C12 DGZ. False 19A D12 XGZ. True 12A A13 UGZ. False 27A C12 MKZ. True 32A C22 DGZ. True 19A D99 XGZ. False
我想要完成的是这个
EmployeeID CollectiveBargainingUnit BusinessGroup ProfitCenter Eligible 1 12A A12 UGZ. True 2 17A B12 MGZ. False 3 18A C12 DGZ. False 4 19A D12 XGZ. True
基于两个数据框(CollectiveBargainingUnit BusinessGroup ProfitCenter)之间的多列,我想在 DF2 中访问它的资格并在 DF1 中更新它
我离开的地方是:
eligibility_map=df2.groupby(["BusinessGroup","ProfitCenter","CollectiveBargainingUnit"]).first()["Eligible"]
df1["Eligible"] = df1["BargainingUnit"].map(eligibility_map).fillna(df1["Eligible"])
我不能只将它映射到一列。我需要一次映射到多个列。
解决方案
推荐阅读
- python - OpenCV 立体校准错误 - (-3:Internal error) CALIB_CHECK_COND - 函数“CalibrateExtrinsics”中输入数组 1 的病态矩阵
- jasper-reports - 如何根据 JasperReports Server 中的另一个多选值列表(复选框)制作多选值列表(复选框)?
- php - 从 Symfony 5 OutputInterface 获取整个控制台输出
- r - 无法在 RStudio Cloud 中使用“webshot”
- swift - 将数据从 Firestore 存储到列表
- javascript - 区分大小写的 Jquery getQuery URL 参数
- jmeter - 如何使用 JMeter 中的 JSON Extractor 返回 JSON 中的最后一个 id
- c# - Azure 中上传的 zip 文件包含无效内容,无法打开
- python - Dask 的并行 for 循环比单核慢
- java - 相对于 5 × 5 2D 阵列的中心逆时针旋转 45 度