min

How do I return a list of the 3 lowest values in another list

丶灬走出姿态 提交于 2020-04-06 09:08:44
问题 How do I return a list of the 3 lowest values in another list. For example I want to get the 3 lowest values of this list: in_list = [1, 2, 3, 4, 5, 6] input: function(in_list, 3) output: [1, 2, 3] 回答1: You can use heapq.nsmallest: >>> from heapq import nsmallest >>> in_list = [1, 2, 3, 4, 5, 6] >>> nsmallest(3, in_list) [1, 2, 3] >>> 回答2: If you could sort,you can get frst 3 elements as below: alist=[6, 4, 3, 2, 5, 1] sorted(alist)[:3] Output: [1,2,3] 回答3: even simpler without modules

find Math.min row

给你一囗甜甜゛ 提交于 2020-03-05 04:58:06
问题 I have already found the lowest value in a column in a csv file, but I can't find which row store this value. Can someone help me please? Is there anyway I can find the answer by myself though I have googled for many days and websites. Thanks in advance. function getDataPointsFromCSV(csv) { var dataPoints = csvLines = []; var mini, a var minIndex = 0 csvLines = csv.split(/[\r?\n|\r|\n]+/); for (var i = 1; i <= csvLines.length; i++) if (csvLines[i] > 0) { points = csvLines[i].split(","); /

min for each row with dataframe in R

心不动则不痛 提交于 2020-02-14 02:42:05
问题 I'm try to do a simple minimum across multiple columns in a data frame but the min function automatically returns the min across the whole of each column rather than for each row separately. I'm sure I'm missing something really simple here? Any ideas much appreciated. x<-c(1,2,7) y<-c(1,5,4) minIwant <- c(1,2,4) df <- data.frame(x,y,minIwant) df$minIget <- min(df$x,df$y) df x y minIwant minIget 1 1 1 1 1 2 2 5 2 1 3 7 4 4 1 回答1: You can use apply to go through each row apply(df, 1, FUN=min)

Select min or max values within one cell (delimited string)

岁酱吖の 提交于 2020-02-04 03:37:04
问题 I have a data frame where for each sample the columns can have multiple values, for example: Gene Pvalue1 Pvalue2 Pvalue3 Beta Ace 0.0381, ., 0.00357 0.01755, 0.001385 0.0037, NA , 0.039 -0.03,1,15 NOS NA 0.02 0.001, 0.00067 0.00009,25,30 I want to apply min() and max() for each gene's data (I have thousands of genes in total) in each column and get the smallest value for the pvalues but the largest value for columns such as the beta. So the output data would look like this: Gene Pvalue1

Select min or max values within one cell (delimited string)

心不动则不痛 提交于 2020-02-04 03:36:27
问题 I have a data frame where for each sample the columns can have multiple values, for example: Gene Pvalue1 Pvalue2 Pvalue3 Beta Ace 0.0381, ., 0.00357 0.01755, 0.001385 0.0037, NA , 0.039 -0.03,1,15 NOS NA 0.02 0.001, 0.00067 0.00009,25,30 I want to apply min() and max() for each gene's data (I have thousands of genes in total) in each column and get the smallest value for the pvalues but the largest value for columns such as the beta. So the output data would look like this: Gene Pvalue1

Max and Min value for each colum of one Dataframe

女生的网名这么多〃 提交于 2020-01-23 12:54:28
问题 Give this dataframe 'x': col1 col2 col3 col4 0 5 -2 1 -5 2 -1 9 3 -7 3 5 How I could get a list of pairs with the min and max of each column? The result would be: list = [ [-5 , 3], [-7 , 5], [-2 , 3], [1 , 9] ] 回答1: You could define a function and call apply passing the function name, this will create a df with min and max as the index names: In [203]: def minMax(x): return pd.Series(index=['min','max'],data=[x.min(),x.max()]) df.apply(minMax) Out[203]: col1 col2 col3 col4 min -5 -7 -2 1 max

Get minimum value between two columns for each row

时间秒杀一切 提交于 2020-01-23 07:42:34
问题 This is my data table: | uid | date | visit | transactionDate | +-----+----------+-------+-----------------+ | 1 | 6/2/2014 | 1 | 6/9/2014 | | 1 | 6/2/2014 | 1 | 8/4/2014 | | 2 | 6/2/2014 | 1 | 8/2/2014 | | 2 | 6/2/2014 | 1 | 10/17/2014 | | 2 | 6/2/2014 | 1 | 10/20/2014 | | 3 | 6/2/2014 | 1 | 6/9/2014 | | 3 | 6/2/2014 | 1 | 6/10/2014 | | 3 | 6/2/2014 | 1 | 6/11/2014 | | 3 | 6/2/2014 | 1 | 6/12/2014 | | 3 | 6/2/2014 | 1 | 6/14/2014 | | 3 | 6/2/2014 | 1 | 6/15/2014 | | 3 | 6/2/2014 | 1 | 6/17

Find which int was minimum in PHP [closed]

十年热恋 提交于 2020-01-22 03:50:47
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I've got 2 integers. I need to know which one has minimum value and get this value. Is there any pretty way (one function?) to do it? Now i'm doing it

Max or min depending on another variable

偶尔善良 提交于 2020-01-17 14:10:06
问题 I need to calculate the max and min of the wave height according to the direction from which it comes, that is to say, I have two variables: Hs (wave height) Direction (direction of the swell) And I need to know the maximum wave height for waves with a direction between 11.25 and 33.75 degrees. For now, use the function: Max (Hs [Direction [11.25: 33.75])) But I do not agree the result with the data that I have. 回答1: Assume your dataframe is called df , your variables are called Hs and

Unique results for SQL command with GROUP, MIN and NULL values

北城余情 提交于 2020-01-15 12:15:47
问题 I have a table inquiry with columns job , gender ( TRUE for women, FALSE for men) and salary . None of the columns is unique, salary may contain NULL . How to find the minimum salary per job for women ( TRUE )? If e.g. there are entries [pilot ; TRUE ; 100] , [pilot ; FALSE ; 100] , [pilot ; TRUE ; NULL] and [pilot ; FALSE ; 120] , the code below returns [pilot ; 100] twice instead of once. SELECT TOP (100) PERCENT T.JOB, T.SALARY FROM INQUIRY AS T INNER JOIN (SELECT JOB, MIN(SALARY) AS SL