3 examples of 'group by count pandas' in Python

Every line of 'group by count pandas' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
90def crosscount(df, col_list):
91 """
92 tools for multy thread bi_count
93 """
94 assert isinstance(col_list, list)
95 assert len(col_list) >= 2
96 name = "count_"+ '_'.join(col_list)
97 df[name] = df.groupby(col_list)[col_list[0]].transform('count')
98 return df
91def apply_counts_to_group(group):
92 """Add the _count and _group_count fields to a group"""
93 if '_subgroup' in group:
94 subgroups = apply_counts(group['_subgroup'])
95 group['_subgroup'] = subgroups
96 group['_count'] = sum(subgroup['_count'] for subgroup in subgroups)
97 group['_group_count'] = len(subgroups)
98 return group
128def group_by(self, dataset, field_name=None):
129 if field_name is None:
130 field_name = self.field_name
131
132 items = self._get_base_set(dataset)
133
134 # Get the min and max
135 min_val, max_val = self._get_range(items, field_name)
136 if min_val is None:
137 return []
138
139 # Get a good bin size
140 bin_size = self._get_bin_size(min_val, max_val)
141
142 # Calculate a grouping variable
143 items = self._add_grouping_value(items, bin_size, field_name)
144
145 # Group by it
146 items = items.values('value')
147
148 # Count the messages in each group
149 result = self._annotate(items)
150
151 return BinnedResultSet(result, bin_size, min_val, max_val)

Related snippets