python - 如何使用列 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
解决方案
我认为你应该使用字典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]
.
推荐阅读
- mysql - 在 ReactNative 应用程序中显示 MySQL 数据
- javascript - 将括号添加到字符串数组中的最小和最大数字
- laravel - Laravel livewire,渲染性能问题。如何管理数百个组件?
- google-cloud-platform - 无法使用 Google 部署管理器将 iam 策略绑定添加到服务帐户
- ios - 如何为 ios 获取旧版本的 expo 客户端应用程序
- angular-schematics - 角度示意图是否可以针对某个随机绝对路径上的路径?
- c++ - 为什么默认隐藏模板基类的公共成员类型?
- python - 防止matplotlib ginput注册点击小部件按钮
- angular - N 个 Mat 表的数据源数组
- javascript - 如何从数组中删除重复值?当数组内的对象属性未定义时,我的代码失败