查找具有指定数字列的最高平均值(平均值)的分类列

时间:2021-05-23 07:40:18

标签: python pandas

import pandas as pd
def category_with_highest_average(df, cat_column, num_column):
    solution = df.groupby(cat_column).mean().sort_values(by=[num_column])
    solution = solution.tail(1)
    return solution
test_case = category_with_highest_average(price_city_df, 'city', 'price')

我已经尝试了上面的代码来解决这个问题。我得到的输出为 价钱 城市 德里 1620.5

预期输出:

德里

我不确定如何只获取城市名称。请帮忙

0 个答案:

没有答案
相关问题