duplicates

R, conditionally remove duplicate rows

纵饮孤独 提交于 2019-11-27 18:12:35
问题 I have a dataframe in R containing the columns ID.A, ID.B and DISTANCE, where distance represents the distance between ID.A and ID.B. For each value (1->n) of ID.A, there may be multiple values of ID.B and DISTANCE (i.e. there may be multiple duplicate rows in ID.A e.g. all of value 4 which each has a different ID.B and distance in that row). I would like to be able to remove rows where ID.A is duplicated, but conditional upon the distance value such that I am left with the smallest distance

RoR nested attributes produces duplicates when edit

孤街浪徒 提交于 2019-11-27 18:05:01
I'm trying to follow Ryan Bates RailsCast #196: Nested model form part 1 . There're two apparent differences to Ryans version: 1) I'm using built-in scaffolding and not nifty as he's using, and 2) I'm running rails 4 (I don't really know what version Ryans using in his cast, but it's not 4). So here's what I did rails new survey2 cd survey2 bundle install rails generate scaffold survey name:string rake db:migrate rails generate model question survey_id:integer content:text rake db:migrate Then I added the associations to the models like so class Question < ActiveRecord::Base belongs_to :survey

Python(pandas): removing duplicates based on two columns keeping row with max value in another column

烂漫一生 提交于 2019-11-27 17:50:25
I have a dataframe which contains duplicates values according to two columns (A and B): A B C 1 2 1 1 2 4 2 7 1 3 4 0 3 4 8 I want to remove duplicates keeping the row with max value in column C. This would lead to: A B C 1 2 4 2 7 1 3 4 8 I cannot figure out how to do that. Should I use drop_duplicates() , something else? JoeCondron You can do it using group by: c_maxes = df.groupby(['A', 'B']).C.transform(max) df = df.loc[df.C == c_maxes] c_maxes is a Series of the maximum values of C in each group but which is of the same length and with the same index as df . If you haven't used .transform

Select one row without duplicate entries

拥有回忆 提交于 2019-11-27 17:42:44
问题 In mysql table info i have : Id , Name , City , date , status I want to select all names from "info" Making the query $query = mysql_query("SELECT name FROM info WHERE status = 1 ORDER BY id") or die(mysql_error()); while ($raw = mysql_fetch_array($query)) { $name = $raw["name"]; echo ''.$name.'<br>'; } Well, the result is that it returns all the entries. I want to echo all the entries without duplicates. Saying: under raw "name" we have inserted the name "John" 10 times. I want to echo only

C# remove duplicates from List<List<int>>

半腔热情 提交于 2019-11-27 17:42:39
问题 I'm having trouble coming up with the most efficient algorithm to remove duplicates from List<List<int>> , for example (I know this looks like a list of int[] , but just doing it that way for visual purposes: my_list[0]= {1, 2, 3}; my_list[1]= {1, 2, 3}; my_list[2]= {9, 10, 11}; my_list[3]= {1, 2, 3}; So the output would just be new_list[0]= {1, 2, 3}; new_list[1]= {9, 10, 11}; Let me know if you have any ideas. I would really appreciate it. 回答1: Build custom of EqualityComparer<List<int>> :

Left Join without duplicate rows from left table

不打扰是莪最后的温柔 提交于 2019-11-27 17:36:44
Please look at the following query: tbl_Contents Content_Id Content_Title Content_Text 10002 New case Study New case Study 10003 New case Study New case Study 10004 New case Study New case Study 10005 New case Study New case Study 10006 New case Study New case Study 10007 New case Study New case Study 10008 New case Study New case Study 10009 New case Study New case Study 10010 SEO News Title SEO News Text 10011 SEO News Title SEO News Text 10012 Publish Contents SEO News Text tbl_Media Media_Id Media_Title Content_Id 1000 New case Study 10012 1001 SEO News Title 10010 1002 SEO News Title

How to find all duplicate from a List<string>?

耗尽温柔 提交于 2019-11-27 17:25:15
I have a List<string> which has some words duplicated. I need to find all words which are duplicates. Any trick to get them all? Giuseppe Ottaviano In .NET framework 3.5 and above you can use Enumerable.GroupBy which returns an enumerable of enumerables of duplicate keys, and then filter out any of the enumerables that have a Count of <=1, then select their keys to get back down to a single enumerable: var duplicateKeys = list.GroupBy(x => x) .Where(group => group.Count() > 1) .Select(group => group.Key); If you are using LINQ, you can use the following query: var duplicateItems = from x in

Remove duplicate records based on multiple columns?

戏子无情 提交于 2019-11-27 17:04:36
I'm using Heroku to host my Ruby on Rails application and for one reason or another, I may have some duplicate rows. Is there a way to delete duplicate records based on 2 or more criteria but keep just 1 record of that duplicate collection? In my use case, I have a Make and Model relationship for cars in my database. Make Model --- --- Name Name Year Trim MakeId I'd like to delete all Model records that have the same Name, Year and Trim but keep 1 of those records (meaning, I need the record but only once). I'm using Heroku console so I can run some active record queries easily. Any

How to output duplicated rows

…衆ロ難τιáo~ 提交于 2019-11-27 16:25:24
I have the following data: x1 x2 x3 x4 34 14 45 53 2 8 18 17 34 14 45 20 19 78 21 48 2 8 18 5 In rows 1 and 3; and 2 and 5 the values for columns X1;X2,X3 are equal. How can I output only those 4 rows, with equal numbers? The output should be in the following format: x1 x2 x3 x4 34 14 45 53 34 14 45 20 2 8 18 17 2 8 18 5 Please, ask me questions if something unclear. ADDITIONAL QUESTION: in the output x1 x2 x3 x4 34 14 45 53 34 14 45 20 2 8 18 17 2 8 18 5 find the sum of values in last column: x1 x2 x3 x4 34 14 45 73 2 8 18 22 You can do this with duplicated , which checks for rows being

Python intersection of two lists keeping duplicates

拜拜、爱过 提交于 2019-11-27 16:07:05
I have two flat lists where one of them contains duplicate values. For example, array1 = [1,4,4,7,10,10,10,15,16,17,18,20] array2 = [4,6,7,8,9,10] I need to find values in array1 that are also in array2, KEEPING THE DUPLICATES in array1. Desired outcome will be result = [4,4,7,10,10,10] I want to avoid loops as actual arrays will contain over millions of values. I have tried various set and intersect combinations, but just couldn't keep the duplicates.. Any help will be greatly appreciated! What do you mean you don't want to use loops? You're going to have to iterate over it one way or another