首页 > 解决方案 > 如何使用列 Dataframe Python 在同一 Dataframe 的另一列中查找值

问题描述

Borrower=[1,1,1,2,2]
Property_type=[Residential, Other, Other, Land, Hotel]
OMV = [100, 50, 30, 102,45]

我已经计算了每个 Borrower&Property_Type 的最大 OMV

OMV_max= [100,100,100,102,102]

现在我会得到

Property_Type_Borrower = [Residential, Residential, Residential, Land, Land]

即我想在 OMV 中找到 OMV_max 并返回 Property_Type

标签: pythonpandasdataframe

解决方案


我认为你应该使用字典OMV_to_Property = OMV_to_Property = {100: 'Residential', 50: 'Other', 30: 'Other', 102: 'Land', 45: 'Hotel'}。然后你可以只使用一个列表推导,比如Property_Type_Borrower = [OMV_to_Property[x] for x in OMV_max].


推荐阅读