aperta.data_processing¶
Tabular helpers that flow through aperta’s (Geo)DataFrame pipeline.
Small composable column-level transforms — dedupe an index after a join, add a straight-line origin→destination distance, take a weighted mean per group. None of these reason about geometry as the primary concern (for that see geo_processing); they operate on tables that may or may not carry a geometry column.
- aperta.data_processing.remove_duplicate_indices(df)[source]¶
Remove duplicate indices from DataFrame or Series. Often useful after spatial join.
- aperta.data_processing.add_straight_line_dist(df, orig_prefix='orig', dest_prefix='dest', out_col='dist_line')[source]¶
Add euclidean origin→destination distance, in CRS units (typically metres).
- aperta.data_processing.weighted_group_mean(values, weights, group_id)[source]¶
Weighted mean of values per group, indexed by group ID.
NaN-aware: rows with NaN in either values or weights are dropped before aggregation. Groups with no surviving rows (or with all weights ≤ 0) yield NaN.
All three inputs must share the same index (per-row alignment); the result is indexed by the unique group IDs. Typical use case: reduce per-cell values to per-zone (group_id = cells[‘zone_id’], weights = cells[‘population’] or similar).
- Parameters:
- Returns:
pd.Series indexed by the unique group IDs, with the weighted mean of values per group.
- Return type: