Reputation: 125
I've to find in the dataset subgroups with similar average for 2 metrics than my original group.
For example, I'd like to find a city or group of cities with the closest average(metric 1) = 10
and average(metric 2) = 5
.
Dataset example:
How can I do it?
Upvotes: 1
Views: 148
Reputation: 1722
Just group by cities and then sort by closes value (I've just added two metric columns, hope that it is ok as I have no details what metric is)
df2 = df.groupby(['city']).mean()
input1 = 10
input2 = 5
df_sort = df2.iloc[((df2['metric 1']-input1)+(df2['metric 2']-input2)).abs().argsort()]
Upvotes: 2