duplicates

fastest way to merge duplicate cells in without looping Excel

此生再无相见时 提交于 2020-06-27 04:15:30
问题 I have cells containing duplicate values that i want to merge quickly. The table looks like this: Sub MergeCells() Application.DisplayAlerts = False Dim n As Name Dim fc As FormatCondition Dim Rng As Range, R As Range Dim lRow As Long Dim I&, J& Dim arr As Variant ReDim arr(1 To 1) As Variant With ThisWorkbook.Sheets("tst") Set Rng = .Range("A2:D11") lRow = Rng.End(xlDown).Row For J = 1 To 4 For I = lRow To 2 Step -1 'last row to 2nd row If Trim(UCase(.Cells(I, J))) = Trim(UCase(.Cells(I - 1,

PHP - Remove duplicates with foreach?

余生颓废 提交于 2020-06-25 04:37:06
问题 I have a array of page numbers: foreach($elements as $el) { $pageno = $el->getAttribute("pageno"); echo $pageno ; } Sadly it contains duplicates. I tried the follow code but it won't return a thing: foreach(array_unique($elements) as $el) { $pageno = $el->getAttribute("pageno"); echo $pageno ; } How to remove the duplicate page numbers? Thanks in advance :) 回答1: Since I do not have your data structure, I am providing a generic solution. This can be optimized if we know the structure of

Assign different colors to different duplicate values in a range

别来无恙 提交于 2020-06-17 10:01:31
问题 I'm trying to have all duplicates in a range highlighted. The twist is I want each different value to have a different color. For example all the values "Apple" would be one color. All the values "Car" would be another color etc. I've found a way to do this, although it can only be run on one Column. I need some help getting it to run on multiple columns. Here is a photo of my example: Here is the VBA code I'm running which currently highlights only column C: Sub different_colourTest2() Dim

Keep duplicates rows in multiple dataframes

梦想的初衷 提交于 2020-06-17 09:38:29
问题 With following dataframes, how do I extract and keep in different dataframes: rows with unique Account only all rows with duplicated Account s I have two datasets, df[0] ...: Account Verified Paid Col1 Col2 Col3 1234 True True ... ... ... 1237 False True 1234 True True 4211 True True 1237 False True 312 False False ...and df[1] : Account Verified Paid Col1 Col2 Col3 41 True True ... ... ... 314 False False 41 True True 65 False False To pass through all dataframes in my list, without

Top N values in 2d array with duplicates to mask

折月煮酒 提交于 2020-05-31 04:08:19
问题 I have 2d numpy array: arr = np.array([[0.1, 0.1, 0.3, 0.4, 0.5], [0.06, 0.1, 0.1, 0.1, 0.01], [0.24, 0.24, 0.24, 0.24, 0.24], [0.2, 0.25, 0.3, 0.12, 0.02]]) print (arr) [[0.1 0.1 0.3 0.4 0.5 ] [0.06 0.1 0.1 0.1 0.01] [0.24 0.24 0.24 0.24 0.24] [0.2 0.25 0.3 0.12 0.02]] I want filter top N values, so I use argsort : N = 2 arr1 = np.argsort(-arr, kind='mergesort') < N print (arr1) [[False False False True True] [ True False False True False] <- first top 2 are duplicates [ True True False

Fast remove consecutive duplicates python

大憨熊 提交于 2020-05-29 04:50:40
问题 My question is similar to this previous SO question I have a very two large lists of data (almost 120 million data points) that contains numerous consecutive duplicates. I would like to remove the consecutive duplicate as follow list1 = [1,1,1,1,1,1,2,3,4,4,5,1,2] #This is 20M long! list2 =[another list of size len(list1)]#This is also 20M long! i = 0 while i < len(list)-1: if list[i] == list[i+1]: del list1[i] del list2[i] else: i = i+1 And the output should be [1, 2, 3, 4, 5, 1, 2]

Conditionally removing duplicates in R

ぃ、小莉子 提交于 2020-05-28 10:49:27
问题 I have a dataset in which I need to conditionally remove duplicated rows based on values in another column. Specifically, I need to delete any row where size = 0 only if SampleID is duplicated . SampleID<-c("a", "a", "b", "b", "b", "c", "d", "d", "e") size<-c(0, 1, 1, 2, 3, 0, 0, 1, 0) data<-data.frame(SampleID, size) I want to delete rows with: Sample ID size a 0 d 0 And keep: SampleID size a 1 b 1 b 2 b 3 c 0 d 1 e 0 Note. actual dataset it very large, so I am not looking for a way to just

Fastest way to remove duplicates in a list without importing libraries and using sets

假如想象 提交于 2020-05-27 10:51:46
问题 I was trying to remove duplicates from a list using the following code: a = [1,2,3,4,2,6,1,1,5,2] res = [] [res.append(i) for i in a if i not in res] But I would like to do this without defining the list I want as an empty list (ie, omit the line res = [] ) like: a = [1,2,3,4,2,6,1,1,5,2] #Either: res = [i for i in a if i not in res] #Or: [i for i in a if i not in 'this list'] # this list is not a string. I meant it as the list being comprehensed I want to avoid library imports and set() 回答1:

Fastest way to remove duplicates in a list without importing libraries and using sets

做~自己de王妃 提交于 2020-05-27 10:51:43
问题 I was trying to remove duplicates from a list using the following code: a = [1,2,3,4,2,6,1,1,5,2] res = [] [res.append(i) for i in a if i not in res] But I would like to do this without defining the list I want as an empty list (ie, omit the line res = [] ) like: a = [1,2,3,4,2,6,1,1,5,2] #Either: res = [i for i in a if i not in res] #Or: [i for i in a if i not in 'this list'] # this list is not a string. I meant it as the list being comprehensed I want to avoid library imports and set() 回答1:

find duplicate rows in a pandas dataframe

ぃ、小莉子 提交于 2020-05-25 17:03:26
问题 I am trying to find duplicates rows in a pandas dataframe. df=pd.DataFrame(data=[[1,2],[3,4],[1,2],[1,4],[1,2]],columns=['col1','col2']) df Out[15]: col1 col2 0 1 2 1 3 4 2 1 2 3 1 4 4 1 2 duplicate_bool = df.duplicated(subset=['col1','col2'], keep='first') duplicate = df.loc[duplicate_bool == True] duplicate Out[16]: col1 col2 2 1 2 4 1 2 Is there a way to add a column referring to the index of the first duplicate (the one kept) duplicate Out[16]: col1 col2 index_original 2 1 2 0 4 1 2 0