Pandas -最低价格和相应的供应商名称

gijlo24d  于 2023-03-28  发布在  其他
关注(0)|答案(1)|浏览(144)

[我目前正在分析一些价格数据,想知道是否可以在pandas dataframe中获得每个通道id的最低费率以及提供最便宜费率的供应商的相应名称]
enter image description here
[Below is my expected output. df'quoted_rates'.idxmin() but it is not giving all the information that I would like to have. Please help me. Appreciate the support, thank you](https://i.stack.imgur.com/SAdBf.png)

njthzxwz

njthzxwz1#

data = [['Supplier 1', 'Lane 1', 'NL', 'DE', 200],
        ['Supplier 2', 'Lane 1', 'NL', 'DE', 150],
        ['Supplier 3', 'Lane 1', 'NL', 'DE', 300],
        ['Supplier 1', 'Lane 2', 'NL', 'DE', 200],
        ['Supplier 2', 'Lane 2', 'NL', 'DE', 105],
        ['Supplier 3', 'Lane 2', 'NL', 'DE', 100]]

columns = ['supplier_name', 'lane_id', 'origin', 'destination', 'quoted_rates']

df = pd.DataFrame(data, columns=columns)
df.sort_values(by='quoted_rates').groupby('lane_id',as_index=False).first()

输出:

lane_id     supplier_name   origin  destination     quoted_rates
0   Lane 1      Supplier 2      NL      DE              150
1   Lane 2      Supplier 3      NL      DE              100

相关问题