ranking

Python Pandas groupby, rank, then assign value based on custom rank

大兔子大兔子 提交于 2019-12-11 03:35:56
问题 Problem Setup The pandas Dataframe df = pd.DataFrame({'Group': ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A'], 'Subgroup': ['Group 1', 'Group 1', 'Group 1', 'Group 1', 'Group 1', 'Group 1', 'Group 2', 'Group 2', 'Group 2'], 'Keyword': ['kw 1', 'kw 1', 'kw 1', 'kw 2', '+kw +2', 'kw 2', 'kw 3', 'kw 3', 'kw 3'], 'Normalized': ['kw 1', 'kw 1', 'kw 1', 'kw 2', 'kw 2', 'kw 2', 'kw 3', 'kw 3', 'kw 3'], 'Criterion Type': ['Exact', 'Phrase', 'Broad', 'Phrase', 'Broadified', 'Exact', 'Broad', 'Exact',

SQL statement using WHERE from a GROUP or RANK

吃可爱长大的小学妹 提交于 2019-12-11 03:09:22
问题 I have a sales snapshot with about 35,000 rows . Let's call the columns: Sales Rep | Account ID | Total Contract Value | Date I need to group everything by Sales Rep and then from there, select that Sales Rep 's top 35 accounts based off of Total Contract Value where the Total Contract Value is >= $10,000 for the Month (Date) of January 2013 . So for example, say John Doe had 294 accounts in this table from January, I only want to see his top 35 accounts >= $10,000 , same for Jane Doe, etc.

Player ranking by categories over months

懵懂的女人 提交于 2019-12-11 02:18:46
问题 Imagine the following Player table, with the fields: PlayerId, Date, Kills and Gold I need to get the player position by category (kills or gold) over months. This is the SELECT: SET @rownumber := 0; SELECT date, rank, kills FROM ( SELECT pla.event_date, @rownumber := @rownumber + 1 AS rank, pla.kills, pla.player_id FROM player AS pla INNER JOIN ... WHERE.pla.event_date >= '2017-09-01' AND pla.event_date <= '2017-12-31' ORDER BY pla.kills DESC ) AS result WHERE player_id = 651894 It works

Javascript Sorting Numbers

江枫思渺然 提交于 2019-12-10 21:04:48
问题 I am trying to sort the number in descending order using javascript. It works well for strings but when I use numbers it gives me wrong results. Following is the code: <html> <head> <script language ="Javascript"> function sort(form) { var a1=form.first.value var b1 = form.second.value var c1 =form.third.value var a2= parseFloat(a1) var b2=parseFloat(b1) var c2= parseFloat(c1) var rank_the_numbers = [a2,b2,c2] rank_the_numbers.sort(function(a, b){return a-b}) document.writeln("The largest

Rank Average with PHP

笑着哭i 提交于 2019-12-10 18:04:07
问题 In Excel there's a function Rank Average (see documentation). I wish to do the same in PHP. Looking online, I find a lot of ranking solutions, but not a lot of those take duplicates into account and when they do, the result I get is not the same as Excel is giving me at all. It's very important it does though. Ideally, what I'd need is a function that requires a score and array to compare it with, and give me the rank for it. Example with some actual date from Excel: $array = array(5.80,6.00

inputs for nDCG in sklearn

本秂侑毒 提交于 2019-12-10 15:01:30
问题 I'm unable to understand the input format of sklearn nDcg: http://sklearn.apachecn.org/en/0.19.0/modules/generated/sklearn.metrics.ndcg_score.html Currently I have the following problem: I have multiple queries for each of which the ranking probabilities have been calculated successfully. But now the problem is calculating nDCG for the test set for which I would like to use the sklearn nDcg. The example given on the link >>> y_true = [1, 0, 2] >>> y_score = [[0.15, 0.55, 0.2], [0.7, 0.2, 0.1]

Algorithm for ordering a list of Objects

∥☆過路亽.° 提交于 2019-12-10 14:17:51
问题 Say you have a List of objects. The User uses mostly all objects when he is working. How can you order the list of objects, so that the list adapts to the order, the users uses mostly? What algorithm can you use for that? EDIT: Many answers suggested counting the number of times an object was used. This does not work, because all objects are used the same amount, just in different orders. 回答1: Inside your object, keep a usedCount. Whenever the object is used, increase this count. Then you can

obtaining 3 most common elements of groups, concatenating ties, and ignoring less common values

爱⌒轻易说出口 提交于 2019-12-10 13:27:46
问题 I am trying to get the 3 most common numbers per group of a dataframe, using a function, but ignoring the less common values (per group), and allowing a unique number if present. Accepted answer will have the lowest system.time #my current function library(plyr) get.3modes.andcounts<- function(origtable,groupby,columnname) { data <- ddply (origtable, groupby, .fun = function(xx){ c(m1 = paste(names(sort(table(xx[,columnname]),decreasing=TRUE)[1])), m2 = paste(names(sort(table(xx[,columnname])

Add a column of ranks

核能气质少年 提交于 2019-12-10 13:26:31
问题 I have some data: test <- data.frame(A=c("aaabbb", "aaaabb", "aaaabb", "aaaaab", "bbbaaa") ) and so on. All the elements are the same length, and are already sorted before I get them. I need to make a new column of ranks, "First", "Second", "Third", anything after that can be left blank, and it needs to account for ties. So in the above case, I'd like to get the following output: A B aaabbb First aaaabb Second aaaabb Second aaaaab Third bbbaaa bbbbaa I looked at rank() and some other posts

SQL ranking query to compute ranks and median in sub groups

廉价感情. 提交于 2019-12-10 03:34:21
问题 I want to compute the Median of y in sub groups of this simple xy_table : x | y --groups--> gid | x | y --medians--> gid | x | y ------- ------------- ------------- 0.1 | 4 0.0 | 0.1 | 4 0.0 | 0.1 | 4 0.2 | 3 0.0 | 0.2 | 3 | | 0.7 | 5 1.0 | 0.7 | 5 1.0 | 0.7 | 5 1.5 | 1 2.0 | 1.5 | 1 | | 1.9 | 6 2.0 | 1.9 | 6 | | 2.1 | 5 2.0 | 2.1 | 5 2.0 | 2.1 | 5 2.7 | 1 3.0 | 2.7 | 1 3.0 | 2.7 | 1 In this example every x is unique and the table is already sorted by x . I now want to GROUP BY round(x) and