Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
74 views

I am trying to group arrays with the same size. The arrays can be grouped if all of the values (30) within the array are the same, so all values must be the same. For example: -1.345509 == -1.345509 ...
Jordi van Selm's user avatar
2 votes
1 answer
62 views

I have to group sub-lists with a common element in set "p", using python. p elements are not always in 1st or las position on the sub-list. Grouped (result) lists is list r. Result list r is ...
Hernan19's user avatar
-1 votes
1 answer
17 views

Hi I have problem with my program, the value of groupby obj can not be get after casting to dict object. from itertools import groupby raw = [ {"name": "A", "age"...
ShIRann's user avatar
3 votes
4 answers
175 views

I have two separate lists each of n elements, with one being ID numbers and the second being pandas dataframes. I will define them as id and dfs. The dataframes in dfs have the same format with ...
verynovice's user avatar
1 vote
1 answer
208 views

I am trying to write a function that takes a list/array and finds the repeated sequence of numbers. Examples: [111, 0, 3, 1, 111, 0, 3, 1, 111, 0, 3, 1] [111, 0, 3, 1] is the block that is being ...
Rashiq's user avatar
  • 451
0 votes
3 answers
105 views

I have a weird situation with a dict which looks like so: a={ "key1":[{"a":10,"b":10,"d":0},{"a":100,"b":100,"d":1},{"a&...
AJW's user avatar
  • 5,923
-3 votes
1 answer
63 views

I'm using Python's itertools.groupby to count consecutive occurrences of elements as mentioned below from itertools import groupby data = [1, 1, 3, 2, 3, 3, 4, 5, 5] sorted_data = sorted(data) groups ...
Partha Pratim Sarma's user avatar
1 vote
2 answers
98 views

I've a dataframe like this, Name COST Timestamp 0 c 8 2023-09-20 15:14:46 1 a 8 2023-09-20 15:14:48 2 c 9 2023-09-20 15:14:55 3 b 10 2023-09-20 15:15:00 4 c 4 2023-...
Starlord22's user avatar
0 votes
2 answers
93 views

I have a list of two element tuples, the first element of each tuple is an integer, these tuples are equivalent to key-value pairs, in fact these tuples are flattened dict_items, generated using list(...
Ξένη Γήινος's user avatar
0 votes
1 answer
68 views

Following is the code weekly = (df.groupby(['Year','Qtr_Year'], as_index=False).agg(High=('High', 'max'),D_HIGH='High','idxmax'))) ...
Yogesh Kamboj's user avatar
-1 votes
2 answers
64 views

How to group or batch the list of elements based on indices sublist ? Below are the possible instances should be considered. Hope that helps better. 1st Instance : Length of elements == sum of all ...
Learner's user avatar
  • 91
0 votes
1 answer
112 views

This is a continuation of my previous question: How to print only if a character is an alphabet? I now have a mapper that is working perfectly, and it's giving me this output when I use a text file ...
Zaku's user avatar
  • 158
-1 votes
1 answer
240 views

I have a class with some fields. I created a list of objects of this class and now I want to group the list by one of the fields inside the objects. It almost works, but unfortunately it shows me only ...
mazix's user avatar
  • 2,630
0 votes
3 answers
54 views

I have this list: [('2023-03-15', 'paris', 'flight', 4), ('2023-03-21', 'berlin', 'flight', 2), ('2023-03-01', 'madrid', 'drive', 10), ('2023-03-04', 'madrid', 'cycling', 3), ('2023-03-08', 'rome', '...
Zen4ttitude's user avatar
1 vote
1 answer
48 views

I tried using itertools.groupby with a pandas Series. But I got: TypeError: boolean value of NA is ambiguous Indeed some of my values are NA. This is a minimal reproducible example: import pandas as ...
Michel de Ruiter's user avatar
0 votes
2 answers
231 views

Here is my list of dicts: [{'subtopic': 'kuku', 'topic': 'lulu', 'attachments': ['ttt'], 'text': 'abc'}, {'subtopic': 'tutu', 'topic': 'lulu', 'attachments': ['pipu'], 'text': 'bubb'}, {'...
SteveS's user avatar
  • 4,100
2 votes
2 answers
200 views

I am working with a data set that is a simple SQL Query that fetches the desired rows. [(2, 5, 'JOHN K', 'YAHOO'), (2, 6, 'AARON M', 'YAHOO'), (2, 7, 'NICK C', 'YAHOO'), (1, 2, 'CELESTE G', 'GOOGLE'), ...
ThinkCode's user avatar
  • 8,011
0 votes
1 answer
208 views

I have one column, and another is datetime which is in index position I done some coding on this. I try to use for loop for below condition but need optimization or list comprehension. date_today = ...
Sushil Kokil's user avatar
0 votes
1 answer
166 views

Suppose I have the below dataframe: >>>from itertools import groupby >>>import pandas as pd >>>idx1 = pd.date_range('2019-01-01',periods=5) >>>idx2 = pd.date_range(...
jgg's user avatar
  • 831
0 votes
1 answer
276 views

I am trying to solve a simple problem using itertools.groupby: group the numbers from 0 to 7 according to the number of 1's in their binary representation. So I want to produce the mapping {0: [0], 1: ...
tBuLi's user avatar
  • 2,345
0 votes
2 answers
68 views

I'd like to group emails by their domain and convert the result into a dictionary. So far I have figured out that itertools.groupby with a custom func will do that. It correctly assigns keys to each ...
t3chb0t's user avatar
  • 19.3k
-3 votes
2 answers
728 views

I have a data structure like this [ (123, 321), (123, 456), (999, 654), (111, 456), (999, 898), (111, 654), (481, 739), ] How can I group the tuples together by any matching element? i....
Mark's user avatar
  • 119
-1 votes
2 answers
733 views

I have list of strings that I want to group together if they contain a specific substring from a master list. Example Input: ["Audi_G71Q3E5T7_Coolant", "Volt_Battery_G9A2B4C6D8E", &...
Gilles's user avatar
  • 11
0 votes
1 answer
1k views

I am a newbie in Rust, and I am having trouble understanding Itertools::GroupBy. Here is an example I came up with to practice GroupBy. Given an array of integers: Group it based on the value of the ...
Lukas's user avatar
  • 69
1 vote
0 answers
110 views

I have a data frame: Id modification_date date1 date2 estimate_date aaa 2022-07-19T13:27:01Z 2022-07-21T20:01:00Z 2022-07-21T22:59:00Z aaa 2022-07-20T13:49:21Z 2022-07-21T20:01:...
RCN's user avatar
  • 111
0 votes
1 answer
62 views

I am trying to write a simple function that gives the result of a runoff vote. I start with a nested list with names of candidates, and I would like to group them by the first element and put that ...
Janek Pawlak's user avatar
0 votes
2 answers
1k views

How in Python to organize and filter a collection of objects by a field value? I need to filter by being equal to an exact value and by being less than a value. And how to do it effectively? If I ...
Sengiley's user avatar
  • 289
0 votes
2 answers
78 views

I have a list of dictionaries like that : a = [ {'user_id':'111','clean_label':'VIR SEPA'}, {'user_id':'112','clean_label':'VIR SEPA'}, {'user_id':'111','clean_label':'VIR SEPA'}, ] and I ...
Quxntin's user avatar
  • 39
0 votes
1 answer
74 views

How to obtain the below result Current Month is the column which is to be calculated. We need to get the increment every month starting from Jan-18 for every account id. Every Account First row/ ...
Karthik_hari1's user avatar
-1 votes
2 answers
104 views

Just having trouble with itertools.groupby. Given a list of dictionaries, my_list= [ "AD01", "AD01AA", "AD01AB", "AD01AC", "AD01AD","AD02", ...
Bgamboa's user avatar
2 votes
2 answers
2k views

I am trying to use the Python itertools.groupby function to change this list: items = [ {'price': 5.0, 'name': 'Strawberries'}, {'price': 5.0, 'name': 'Strawberries'}, {'price': 5.0, 'name': '...
Mz_22's user avatar
  • 53
0 votes
1 answer
53 views

I am trying to group .xls files in list infiles based on strings in the .xls file names. The file names are formatted like this "type_d_cross_profile_glacier_name_A-Z" where type_d is a type ...
user avatar
1 vote
4 answers
326 views

I have a large list of tuples where each tuple contains 9 string elements: pdf_results = [ ("Kohl's - Dallas", '-', "Kohl's Cafe", '03/18/22', 'RC', '8', '0', '16', '8'), ("...
ericdwkim's user avatar