group-by

Save grouped by results into separate CSV files

为君一笑 提交于 2019-12-17 16:53:20
问题 I have a code for create groups with CSV data and create new files with that groups too! I read my csv file and then work with that. The problem is when my funtion works and create the new files with the data, the name of the new files is the name of the group and I don´t want that: ID Inventory Domain Requests Impressions Fill Rate 123456 au_to/8 neighborhoodscout.com 11402 26 0.23 123456 au_to/8 sinembargo.mx 10334 24 0.23 123456 au_to/8 elsalvadortimes.com 9893 17 0.17 155444 cami_oneta/8

pandas groupby count string occurrence over column

孤街浪徒 提交于 2019-12-17 16:46:23
问题 I want to count the occurrence of a string in a grouped pandas dataframe column. Assume I have the following Dataframe: catA catB scores A X 6-4 RET A X 6-4 6-4 A Y 6-3 RET B Z 6-0 RET B Z 6-1 RET First, I want to group by catA and catB . And for each of these groups I want to count the occurrence of RET in the scores column. The result should look something like this: catA catB RET A X 1 A Y 1 B Z 2 The grouping by two columns is easy: grouped = df.groupby(['catA', 'catB']) But what's next?

return count 0 with mysql group by

被刻印的时光 ゝ 提交于 2019-12-17 16:45:20
问题 database table like this ============================ = suburb_id | value = 1 | 2 = 1 | 3 = 2 | 4 = 3 | 5 query is SELECT COUNT(suburb_id) AS total, suburb_id FROM suburbs where suburb_id IN (1,2,3,4) GROUP BY suburb_id however, while I run this query, it doesn't give COUNT(suburb_id) = 0 when suburb_id = 0 because in suburbs table, there is no suburb_id 4, I want this query to return 0 for suburb_id = 4, like ============================ = total | suburb_id = 2 | 1 = 1 | 2 = 1 | 3 = 0 | 4

GroupingError: ERROR: column “ ” must appear in the GROUP BY clause or be used in an aggregate function

£可爱£侵袭症+ 提交于 2019-12-17 16:40:46
问题 I am trying to create a list of unique patients who have left comments. The code words fine until I upload to heroku where it doesnt work in postgresql. This is my Ruby .erb code to create the list: <% @comments.group(:patient_id).each_with_index do |comment, index| %> <div class="profile-post color-one"> <span class="profile-post-numb"><%= index+1 %></span> <div class="profile-post-in"> <h3 class="heading-xs"><a><%= link_to "#{comment.patient.first_name} #{comment.patient.last_name}",

Concatenate one field after GROUP BY

狂风中的少年 提交于 2019-12-17 16:31:30
问题 This question have been asked many times in SO but none of the answers is satisfying to my situation. Question 1 Question 2 Question 3 Question 4 I am dealing with a DataObjectVersions table that contains multiple versions for around 1.2 million unique objects (and increasing). I need to concatenate changes from a specific field for each unique object. Right now I am using the solution with the XML Path presented in Q3 but running such a query on this table is a total performance disaster.

linq distinct or group by multiple properties

只谈情不闲聊 提交于 2019-12-17 15:46:46
问题 How can I using c# and Linq to get a result from the next list: var pr = new List<Product>() { new Product() {Title="Boots",Color="Red", Price=1}, new Product() {Title="Boots",Color="Green", Price=1}, new Product() {Title="Boots",Color="Black", Price=2}, new Product() {Title="Sword",Color="Gray", Price=2}, new Product() {Title="Sword",Color="Green",Price=2} }; Result : {Title="Boots",Color="Red", Price=1}, {Title="Boots",Color="Black", Price=2}, {Title="Sword",Color="Gray", Price=2} I know

Android: Distinct and GroupBy in ContentResolver

梦想与她 提交于 2019-12-17 15:25:18
问题 What would be the correct way to add DISTINCT and/or GROUPBY to ContentResolver -based queries? Right now I have to create custom URI for each special case. Is there a better way? (I still program for 1.5 as lowest common denominator) 回答1: You can do nice hack when querying contentResolver, use: String selection = Models.SOMETHING + "=" + something + ") GROUP BY (" + Models.TYPE; 回答2: Since no one came to answer I'm just going to tell how I solved this. Basically I would create custom URI for

What does SQL clause “GROUP BY 1” mean?

寵の児 提交于 2019-12-17 15:11:56
问题 Someone sent me a SQL query where the GROUP BY clause consisted of the statement: GROUP BY 1 . This must be a typo right? No column is given the alias 1. What could this mean? Am I right to assume that this must be a typo? 回答1: It means to group by the first column regardless of what it's called. You can do the same with ORDER BY . 回答2: SELECT account_id, open_emp_id ^^^^ ^^^^ 1 2 FROM account GROUP BY 1; In above query GROUP BY 1 refers to the first column in select statement which is

Show all dates between, even if no result

别来无恙 提交于 2019-12-17 12:46:24
问题 SELECT User_JoinDate, COUNT(User_ID) FROM Users WHERE `User_JoinDate` BETWEEN '2012-11-22' AND '2012-12-06' GROUP BY User_JoinDate ORDER BY User_JoinDate ASC" I'm generating data to be displayed in a line graph. Unfortunately I can't figure out how to get the above query to display 0 for a date that no users might have registered. So currently my output might be something like this: 2012-11-22 - 2 2012-11-25 - 4 But what I want is 2012-11-22 - 2 2012-11-23 - 0 2012-11-24 - 0 2012-11-25 - 4 I

How to group by DESC order

混江龙づ霸主 提交于 2019-12-17 11:24:27
问题 I have the following table called questions: ID | asker 1 | Bob 2 | Bob 3 | Marley I want to select each asker only once and if there are multiple askers with the same name, select the one of the highest id. So, the expected results: ID | asker 3 | Marley 2 | Bob I use the following query: SELECT * FROM questions GROUP by questions.asker ORDER by questions.id DESC I get the following result: ID | asker 3 | Marley 1 | Bob So it selects the first 'Bob' it encounters instead of the last one.