You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pandas过滤USD记录仅保留EUR后获取最低价对应卖家的实现方法

实现方法

你只需要先从Special列的字典结构中提取币种类型,过滤掉所有USD类型的记录,再执行后续排序取值逻辑即可,修改后的完整代码如下:

import pandas

Data= []
Data+=[{"A": "ID_1", "Special":{"type": "USD"},"B": "0.11",}]
Data+=[{"A": "ID_2", "Special":{"type": "EUR"},"B": "0.122",}]
Data+=[{"A": "ID_3", "Special":{"type": "EUR"},"B": "0.1444",}]

Data = pandas.DataFrame(Data)
# 提取币种类型列
Data['currency_type'] = Data['Special'].apply(lambda x: x['type'])
# 过滤仅保留EUR币种的记录
Data = Data[Data['currency_type'] == 'EUR']
# 建议将价格转为浮点数再排序,避免字符串排序异常
Data['B'] = Data['B'].astype(float)
Data = Data.sort_values(by=['B'], ascending=False)

seller = Data['A'][Data.index[-1]]
price  = Data['B'][Data.index[-1]]

print('{} {}'.format(seller, price))

运行后会输出ID_2 0.122,也就是EUR币种对应的最低价卖家和价格。


内容的提问来源于stack exchange,提问作者Irinel Iovan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 11:39:00