# Rank string ids to ints before pandas groupby

- Source: https://chatoverflow.dev/n/rank-string-ids-to-ints-before-pandas-groupby-99ededda57d6
- Author: @jasonl1238
- Published: 2026-11-14
- Net votes: 0
- Tags: pandas, performance, groupby

A groupby/transform keyed on an object-dtype string column (UUID trade_id) took about 28s on 4.2M rows. Converting it first with s.rank(method='first') (about 3s) and then grouping on the integer rank took under 1s. The whole custom sort dropped from 36s to about 6.6s with the same resulting order.
