Questions tagged [group]
585 questions
2
votes
1 answer
Create new column with ratio values based on multiple other columns in python pandas
I'm a python newbie and getting a bit lost in how to transform my data.
Here's an example dataset:
import numpy as np
import pandas as pd
import random
random.seed(123)
df = pd.DataFrame({'pp': list(range(1, 11)), 'age':…

Inkling
- 469
- 1
- 4
- 19
2
votes
3 answers
How to create a group based on pattern from another column?
I have a data frame as below,
dt <- data.frame(id = c("a","b","c","d","e","f","g","h","i","j"),
value = c(1,2,1,2,1,1,1,2,1,2))
> dt
id value
1 a 1
2 b 2
3 c 1
4 d 2
5 e 1
6 f 1
7 g 1
8 …

ds_worthington
- 121
- 8
2
votes
1 answer
Numpy array - Regroup values when index equals a specified value
I'm pretty new to numpy arrays, and was not able to find a good explanation / example for my issue. I saw things like take() or take_along_axis() but I didn't understood what was going on...
I have this 2D numpy, which may contain N sub-arrays, of…

Felix
- 31
- 2
2
votes
1 answer
R: Add count for unique values within Group, disregarding other variables within dataframe
I would like to add a new variable to my data frame, which, for each group says the number of unique entries with relation to one variable (state), while disregaring others.
Data input
df <- data.frame(id=c(1,2,3,4,5,6,7,8,9),
…

mclofa
- 33
- 5
2
votes
1 answer
How do I merge arrays from multiple documents without duplicates in MongoDB aggregation?
I have 3 documents:
{
"id": 1,
"user": "Brian1",
"configs": [
"a",
"b",
"c",
"d"
]
}
----
{
"id": 2,
"user": "max_en",
"configs": [
"a",
"h",
"i",
"j"
]
}
----
----
{
"id": 3,
"user":…

TheStranger
- 1,387
- 1
- 13
- 35
1
vote
1 answer
Ansible - How to regroup a list of dicts based on dict attribute
I have a list of dicts. For simplicity, it contains Country/State/City/Street details
{
"addresses": [
{
"Name": "North_America",
"Id": 10001,
"Type": "Country",
"Parent_Id": 10000
…

piercjs
- 133
- 8
1
vote
2 answers
Create count table for specific condition and then add column that creates count by group as a whole in R
I have a table like this:
data1 <- data.frame("State" = c("NJ", "NJ", "PA", "NJ", "TX"), "Filter" = c("Filter", "Filter",
"No Filter", "Filter", "Filter"), "Threshold" = c("Exceeds","Exceeds", NA, "NL", "Exceeds"))
I'd like to create a count table…

Sarah
- 411
- 4
- 14
1
vote
1 answer
How to rename ggplot legend when plot is based on interaction of multiple factor levels?
I am unable to figure out how to edit the legend title for plots involving different line types and colors representing the interaction of factors and their levels.
The sample script below produces the desired plot for two factors each with two…

Herb
- 21
- 2
1
vote
1 answer
Sampling the rows randomly by the specific rules in R
I have dat1 and dat2 like this:
dat1<-data.frame(company=c("a","b","c"),
random=c(2,1,1),
prior=c(1,3,1))
dat2<-data.frame(company=c("a","a",'a',"b","b","a","a","c","c","c",
…

Lee
- 369
- 1
- 6
1
vote
1 answer
split vector into chunks in R and group similar items
I'm trying to split a vector (that is changing eveytime) into chunks, however same values have to belong to the same chunk. The number of chunks can vary but can be at least 4, or that the chunks are of equal frequencies.
For example, here is a…

Jinane Jouni
- 37
- 6
1
vote
1 answer
Oracle Select and Group By
I have the below table.
create table cricket(team1 varchar2(22),team2 varchar2(22));
select * from cricket
Team1 Team2
INDIA SL
SL AUS
SA ENG
ENG NZ
AUS INDIA
in the above table i want to display the count of teams
played.
for…

Ram
- 727
- 2
- 16
- 33
1
vote
1 answer
group array of objects and get the count in mongodb
I am having an array of objects:
[
{
medicationDetails: {
category: 'Asthma',
subCategory: '',
providedBy: 'Doctor'
}
},
{
medicationDetails: {
category: 'Diabetes',
subCategory: 'Oral',
…

Code The World
- 141
- 9
1
vote
2 answers
R function to summarise using dplyr group_by with flexibble groups, including no grouping at all
I want to write an R function using dplyr to summarise a data set that accepts different numbers of grouping variables to the group_by statement - including no grouping at all. I have found answers to similar questions that use 'group_by_', but…

AdrianD
- 41
- 6
1
vote
1 answer
How can I display users a, b, and c with their corresponding sum of money using group by and sum in MySQL join?
mysql> select * from bills;
+----+------+-------+---------------------+---------------------+
| id | user | money | created_at | updated_at |
+----+------+-------+---------------------+---------------------+
| 1 | a | 100 |…

Patrick Su
- 11
- 3
1
vote
1 answer
group multiple fields and get respective counts using mongodb
I am having some data:
{
medicationDetails: {
category: 'Asthma',
subCategory: ''
}
},
{
medicationDetails: {
category: 'Diabetes',
subCategory: 'Oral'
}
},
{
medicationDetails: {
category: 'Asthma',
subCategory:…

Code The World
- 141
- 9