#GroupBy
Wait, RxJS has a `groupBy` operator?

This changes everything!

#RxJS #Angular #TypeScript #WebDev
November 17, 2026 at 11:29 AM
Zero 1.12 is out 🎉

• Synced aggregates: count(), sum(), avg(), min(), max()
• groupBy() and distinct()
• JSON path filters
• React Native cold start about 3x faster
• zero-cache uses up to 1.8x less CPU

zero.rocicorp.dev/docs/release...
Zero 1.12
Synced Aggregates and JSON Path Filters
zero.rocicorp.dev
November 12, 2026 at 3:34 PM
Found online

In a Windows 11 Explorer window, Group by is in the Sort menu.

In a file Open/Save dialog, you have to rightclick the white space (background) to a get the Groupby option.

note that (None) only appears when the folder is currently grouped by some attribute, such as Date modified.
November 13, 2026 at 1:11 AM
Python: xử lý dữ liệu lớn tiết kiệm bộ nhớ bằng itertools — islice, chain và groupby trong 5 phút

Khi dữ liệu lớn hơn RAM, cách đúng không phải đọc hết vào list rồi mới tính, mà là xử lý theo luồng — tính tới đâu, đọc tới đó. Module itertools trong thư viện chuẩn sinh ra cho việc này: các hàm của…
Python: xử lý dữ liệu lớn tiết kiệm bộ nhớ bằng itertools — islice, chain và groupby trong 5 phút
Khi dữ liệu lớn hơn RAM, cách đúng không phải đọc hết vào list rồi mới tính, mà là xử lý theo luồng — tính tới đâu, đọc tới đó. Module itertools trong thư viện chuẩn sinh ra cho việc này: các hàm của nó trả về iterator lười, chỉ tạo phần tử khi bạn duyệt tới. Bài này dùng ba hàm hay gặp nhất — …
linhfish.dev
November 16, 2026 at 9:09 AM
pandas explode() on a List Column: Turning Stock-to-Concept Tags into a Lookup Table, a Co-occurrence Matrix and Back Again
Tagging data often arrives as one row per entity with a list of tags in a single cell. A stock has several concept or theme tags, an article has several topics, a product sits in several categories. That shape is easy to store and hard to analyse. You cannot `groupby` a list, `value_counts` on a list column counts whole lists, and a join on a tag is impossible until each tag has its own row. `DataFrame.explode()` is the pandas tool for this. It takes a column of lists and produces one row per element, repeating the other columns. This tutorial walks through explode on a small table of stocks and concept tags, covering the parts that cause bugs in real data: mixed cell types, empty lists and `None`, duplicate tags, the index that explode leaves behind, exploding two columns together, and the reverse operation. It ends with a tag lookup, tag counts and a co-occurrence matrix, which together answer "which stocks carry this concept?" and "which concepts tend to appear together?" Everything runs on pandas 3.1. The tickers and company names are placeholders. ## The starting table, with realistic mess Real tag data is rarely clean. This table contains the four shapes you will meet in practice: a normal list, a list with a duplicate, a delimited string that never got parsed, an empty list and a missing value. import numpy as np import pandas as pd df = pd.DataFrame({ "ticker": ["A01", "A02", "A03", "A04", "A05", "A06"], "name": ["Alpha Cells", "Beta Robotics", "Gamma Chips", "Delta Grid", "Epsilon Cloud", "Zeta Motors"], "concepts": [ ["solid-state battery", "energy storage"], ["humanoid robot", "AI compute"], ["AI compute", "chip packaging", "AI compute"], # duplicate tag "energy storage; grid upgrade", # unparsed string [], # no tags None, # missing ], }) ## What explode() does by default long = df.explode("concepts") print(long) ticker name concepts 0 A01 Alpha Cells solid-state battery 0 A01 Alpha Cells energy storage 1 A02 Beta Robotics humanoid robot 1 A02 Beta Robotics AI compute 2 A03 Gamma Chips AI compute 2 A03 Gamma Chips chip packaging 2 A03 Gamma Chips AI compute 3 A04 Delta Grid energy storage; grid upgrade 4 A05 Epsilon Cloud NaN 5 A06 Zeta Motors NaN Five behaviours are visible here, and each one matters: 1. **The index repeats.** Every element keeps its parent's index label, so label `0` now appears twice. Anything that assumes a unique index, such as `.loc[0]` returning a single row or an index-aligned assignment, will behave differently. 2. **Strings are not split.** A string is a scalar to explode, so `"energy storage; grid upgrade"` passes through as one tag. Explode only expands list-likes: lists, tuples, sets, Series and NumPy arrays. 3. **Empty lists become NaN.** `[]` produces one row with a missing value, not zero rows. The entity is kept. 4. **None becomes NaN.** Same result as the empty list. 5. **Duplicates survive.** `AI compute` appears twice for A03. Behaviours 3 and 4 are actually helpful: explode never silently drops an entity. Whether you keep those rows is a decision you make next, explicitly. ## Normalise the cells before exploding The reliable pattern is to coerce every cell to a clean Python list first, then explode. A small function handles every shape above: def to_list(v): if v is None or (isinstance(v, float) and np.isnan(v)): return [] if isinstance(v, str): return [p.strip() for p in v.split(";") if p.strip()] return list(v) df["concepts"] = df["concepts"].map(to_list) Then explode with `ignore_index=True` to get a fresh, unique index, drop the empty-tag rows, remove duplicate pairs, and normalise case and whitespace: long = (df.explode("concepts", ignore_index=True) .dropna(subset=["concepts"]) .drop_duplicates(["ticker", "concepts"])) long["concepts"] = long["concepts"].str.strip().str.lower() print(long) ticker name concepts 0 A01 Alpha Cells solid-state battery 1 A01 Alpha Cells energy storage 2 A02 Beta Robotics humanoid robot 3 A02 Beta Robotics ai compute 4 A03 Gamma Chips ai compute 5 A03 Gamma Chips chip packaging 7 A04 Delta Grid energy storage 8 A04 Delta Grid grid upgrade Note the gap at index 6: that was A03's duplicate `AI compute`, removed by `drop_duplicates`. If you need a contiguous index after filtering, add `.reset_index(drop=True)`. Two ordering decisions in this pipeline deserve a comment: * **Normalise case before deduplicating, if variants exist.** Here the duplicate was an exact match, so the order did not matter. If one source writes `AI Compute` and another `ai compute`, lower-case first, then drop duplicates, otherwise both survive. * **`dropna` removed A05 and A06.** That is correct for a lookup table, but if you later compute "share of stocks with at least one tag", count from the original `df`, not from `long`. For a single delimited string column you can skip the function entirely and chain `str.split` with explode: s = pd.Series(["energy storage; grid upgrade", "AI compute"]) print(s.str.split(";").explode().str.strip()) 0 energy storage 0 grid upgrade 1 AI compute dtype: str ## Tag lookup and tag counts With one row per (ticker, concept) pair, the common questions become one-liners. Which stocks carry each concept: lookup = long.groupby("concepts")["ticker"].agg(list).to_dict() print(lookup) {'ai compute': ['A02', 'A03'], 'chip packaging': ['A03'], 'energy storage': ['A01', 'A04'], 'grid upgrade': ['A04'], 'humanoid robot': ['A02'], 'solid-state battery': ['A01']} How many stocks each concept covers: print(long["concepts"].value_counts()) concepts energy storage 2 ai compute 2 solid-state battery 1 humanoid robot 1 chip packaging 1 grid upgrade 1 Name: count, dtype: int64 Because duplicates were dropped per ticker, these counts are numbers of distinct stocks, not numbers of tag mentions. Without the `drop_duplicates` step, `ai compute` would show 3, overstating its coverage by one stock. With six rows the error is obvious. With 5,000 stocks and tags merged from three vendors, it is not. The long table is also the right shape for joins. If you have a second table of daily metrics per ticker, `long.merge(metrics, on="ticker")` attaches them to every concept the ticker belongs to, and a `groupby("concepts")` then aggregates the metric per concept. ## A one-hot matrix and a co-occurrence matrix `pd.crosstab` turns the long table into a ticker-by-concept indicator matrix: wide = pd.crosstab(long["ticker"], long["concepts"]) print(wide) concepts ai compute chip packaging energy storage grid upgrade humanoid robot solid-state battery ticker A01 0 0 1 0 0 1 A02 1 0 0 0 1 0 A03 1 1 0 0 0 0 A04 0 0 1 1 0 0 Multiplying the transpose by the matrix itself counts, for every pair of concepts, how many stocks carry both: co = wide.T @ wide print(co) concepts ai compute chip packaging energy storage grid upgrade humanoid robot solid-state battery concepts ai compute 2 1 0 0 1 0 chip packaging 1 1 0 0 0 0 energy storage 0 0 2 1 0 1 grid upgrade 0 0 1 1 0 0 humanoid robot 1 0 0 0 1 0 solid-state battery 0 0 1 0 0 1 The diagonal repeats the per-concept counts. Off-diagonal cells show overlap: `energy storage` shares one stock each with `grid upgrade` and `solid-state battery`, while `ai compute` overlaps with both `chip packaging` and `humanoid robot`. On a real universe, this matrix is the input for normalised overlap measures (divide by the smaller diagonal value, or compute Jaccard similarity) and for clustering concepts into broader groups. If you only have the raw delimited strings and need indicators quickly, `str.get_dummies` does the split and one-hot in one call: print(pd.Series(["energy storage;grid upgrade", "AI compute"]).str.get_dummies(sep=";")) AI compute energy storage grid upgrade 0 0 1 1 1 1 0 0 It splits on the exact separator, so strip spaces around delimiters first or you will get columns like `" grid upgrade"`. ## Exploding two columns together Sometimes each tag has a paired value, for example a relevance weight. Since pandas 1.3, `explode` accepts a list of columns and expands them in lockstep: d2 = pd.DataFrame({ "ticker": ["A01", "A02"], "concepts": [["solid-state battery", "energy storage"], ["humanoid robot", "AI compute"]], "weight": [[0.7, 0.3], [0.6, 0.4]], }) e = d2.explode(["concepts", "weight"]) print(e) print(e.dtypes) ticker concepts weight 0 A01 solid-state battery 0.7 0 A01 energy storage 0.3 1 A02 humanoid robot 0.6 1 A02 AI compute 0.4 ticker str concepts str weight object dtype: object Two catches. The lists in each row must have the same length, or pandas raises `ValueError: columns must have matching element counts`. And the exploded numeric column comes out as `object` dtype, because it was a column of Python lists. Convert it before doing arithmetic: e = e.astype({"weight": "float64"}) Exploding the two columns separately and joining them afterwards is a common mistake. It produces a Cartesian product within each row (four rows per ticker here instead of two) and silently pairs every concept with every weight. ## Going back: from long to lists The inverse of explode is a `groupby` with list aggregation: back = long.groupby("ticker")["concepts"].agg(sorted) print(back) ticker A01 [energy storage, solid-state battery] A02 [ai compute, humanoid robot] A03 [ai compute, chip packaging] A04 [energy storage, grid upgrade] Name: concepts, dtype: object Sorting inside the aggregation makes the output deterministic, which helps when you diff tag snapshots from two dates to see which concepts were added or removed. A05 and A06 are absent because they had no tags. If you need every ticker, `back.reindex(df["ticker"], fill_value=[])` restores them with empty lists. ## Performance `explode` is vectorised and fast. On a synthetic frame with 200,000 rows and three tags each, it produced 600,000 rows in about 0.05 seconds on the test machine. A pure-Python list comprehension over `zip(ticker, concepts)` building the same rows took about 0.17 seconds. The common `df.apply(lambda row: pd.Series(row["concepts"]), axis=1).stack()` pattern from older answers is far slower than both and worth replacing wherever you find it. ## FAQ **Why does`explode` keep NaN rows instead of dropping them?** So that no entity disappears by accident. An empty list or missing value becomes one row with NaN. Use `dropna(subset=[col])` when you want them gone. **How do I explode a column that contains JSON strings like`'["a", "b"]'`?** Parse first: `df[col] = df[col].map(json.loads)`, then explode. Explode treats any string as a single scalar. **Does explode work on a Series?** Yes. `Series.explode()` behaves the same way and also accepts `ignore_index=True`. ## Conclusion `pandas explode` on a list column is the step that turns tag data into something you can count, join and compare. Normalise every cell to a real list first, explode with `ignore_index=True`, drop empty rows and duplicate pairs on purpose, and convert dtypes after exploding paired columns. From the long table, a lookup, distinct counts, a one-hot matrix and a co-occurrence matrix each take a single line, and a list-aggregating `groupby` takes you back. To see the same idea applied to maintained A-share concept tags, Lava's concept stocks lookup lists the stocks attached to each theme. 中文简介:本文讲 pandas explode() 如何处理“列表列”:以股票-概念标签表为例,说明 explode 的默认行为(索引重复、字符串不拆分、空列表与 None 变 NaN、重复标签保留),给出先规整为列表再展开、去空去重的稳妥写法;接着用展开后的长表做概念反查、按概念计股票数、crosstab 独热矩阵与共现矩阵;还覆盖多列同步展开、groupby 还原为列表以及性能对比。示例数据为占位样本,仅作方法演示。
dev.to
November 16, 2026 at 8:43 PM
Family Groupby Henry Moore. Tate Britain.
November 7, 2026 at 8:47 AM
Day 24/90 C#: EF Core logging caught my monthly report running one query three times. Count() for the subject line, GroupBy for the summary, foreach for the rows -- each one a fresh SELECT of 18k rows.

ToList() once, then shape in memory. The operators never need the database.

#CSharp #DotNet
November 10, 2026 at 12:25 AM
GroupBy + Last() keeps the right elements in the wrong order. A DistinctLastBy that keeps source order, checked and benchmarked.
https://startdebugging.net/2026/11/how-to-distinctby-keep-the-last-element-in-csharp-preserving-order/?utm_source=bluesky&utm_medium=social&utm_campaign=auto
November 8, 2026 at 12:06 PM
📦 protich/auto-join-eloquent 0.11.2

Extend Eloquent to support auto-joining relationships and aliasing for SELECT, WHERE, ORDERBY, GROUPBY and HAVING clauses

🔗 https://github.com/protich/auto-join-eloquent
October 31, 2026 at 5:10 PM
Reading the "Snowed In All Alone, Together" prompt fest post, and this prompt kinda got my brain going. Made me think of "The Birds" (du Maurier). Kinda wanna see characters stuck in that kind of situation...
(snowedinalonetogether.dreamwidth.org)
October 31, 2026 at 9:59 PM
Using xs on a multi-indexed #Python #Pandas data frame drops the named level — unless you use drop_level=False:

(
pd
.read_parquet('taxi_2025-11.parquet')
.groupby(['passenger_count', 'VendorID'])['total_amount'].mean()
.xs(1, level=1, axis='index', drop_level=False)
)
October 29, 2026 at 8:28 PM
Money comes from Cost Explorer, not Config:

Filter: Tags {Key: team, MatchOptions: [ABSENT]}
GroupBy: RESOURCE_ID

Resource-level cost only covers the last 14 days, but that is enough to rank findings by dollars instead of by count.
October 30, 2026 at 1:16 AM
Grab part of a #Python #Pandas data frame with multi-indexed columns with xs, specifying axis='columns':

(
pd
.read_parquet('nyc_taxi_2025-11.parquet')
.groupby('passenger_count')[['trip_distance', 'total_amount']].agg(['mean', 'std'])
.xs('std', level=1, axis='columns')
)
October 27, 2026 at 7:22 PM
If you try it, the spreadsheet is already a good spec: export it to CSV, load it with pandas, and a groupby on month and category gets you most of that aggregated view. Charts or a small web page can come later. Rebuilding a tool you use every day is a nice way to learn.
October 28, 2026 at 12:38 PM
To retrieve from a multi-indexed #Python #Pandas data frame/series based on an inner index layer, use xs ("cross section"):

(
pd
.read_parquet('nyc_taxi_2025-11.parquet')
.groupby(['passenger_count', 'VendorID'])['total_amount'].mean()
.xs(1, level='VendorID')
)
October 26, 2026 at 6:02 PM
To retrieve all rows from a multi-indexed #Python #Pandas data frame or series, specifying the two outer layers, pass a tuple (not a list!):

(
pd
.read_parquet('nyc_taxi_2025-11.parquet')
.groupby(['passenger_count', 'VendorID'])['total_amount'].mean()
.loc[(1.0, 1)]
)
October 25, 2026 at 4:30 PM
To retrieve all rows from a multi-indexed #Python #Pandas data frame or series based on the outermost index, use "loc":

(
pd
.read_parquet('/Users/reuven/Data/nyc_taxi_2025-11.parquet')
.groupby(['passenger_count', 'VendorID'])['total_amount'].mean()
.loc[1.0]
)
October 24, 2026 at 6:05 PM
I upgraded to Office 2024 for Excel only to find it doesn't include years-old new 365 functions like PIVOTBY and GROUPBY. 🤬
October 23, 2026 at 10:53 PM
Python itertools By Example
tech_blogs_real_python

#Python
Python itertools By Example
Master Python's itertools module by building practical examples with batched(), pairwise(), groupby(), and more, and learn to think iteratively.
realpython.com
October 22, 2026 at 2:36 PM
Want to avoid tons of NaNs when grouping with Grouper in #Python #Pandas?

Trim the dates to avoid extremes:

(
df
.loc[ pd.col('tpep_pickup_datetime').dt.month == 11 ]
.groupby(pd.Grouper(key='tpep_pickup_datetime', freq='14D'))['trip_distance'].mean()
)
October 18, 2026 at 3:50 PM
Got NaNs when using Grouper on a #Python #Pandas data frame?

groupby+Grouper chops up the datetime values, from the earliest to the latest, by the specified granularity.

If even one datetime is super early/late, you'll get tons of NaNs.

dropna is often helpful here.
October 17, 2026 at 5:47 PM
If you have a datetime column in your #Python #Pandas data frame, you can groupby on the output of a dt method, such as day_name:

df.groupby(df['tpep_pickup_datetime'].dt.day_name())['trip_distance'].mean()

The above gives the mean trip_distance for each day.
October 15, 2026 at 3:30 PM
Call multiple methods in a #Python #Pandas groupby with agg. Pass a list of strings (method names), and get a data frame back, one column per method.

df.groupby('passenger_count')['total_amount'].agg(['mean', 'std'])

Here, both methods (mean and std) are computed per group.
October 10, 2026 at 3:30 PM
Pandas for Beginners: From a Messy Table to a First Insight by Saurabh Anand saurabhanand56.medium.com/pandas-for-b...
Pandas for Beginners: From a Messy Table to a First Insight
A small, hypothetical orders dataset taken through load, inspect, clean, filter and groupby, with every output checked.
saurabhanand56.medium.com
October 10, 2026 at 5:32 AM