The area_to_pandas function has been optimized to significantly improve its execution speed.
Set lookups: Areas are converted to sets for O(1) membership checks, making the isin operations more efficient.
Vectorization: Replaced loop-based calculations with vectorized operations for total_travel_time and total_free_time, leveraging the power of numpy and pandas to perform these operations in bulk.
Single DataFrame access: Minimized repeated access to DataFrame columns, reducing the overhead of these operations.
Efficient grouping: Used unique() and nunique() for faster unique element counting.
In my testing of a large simulation, this sped up the function from ~75 seconds to ~2.5 seconds (about 30x).
The
area_to_pandas
function has been optimized to significantly improve its execution speed.isin
operations more efficient.total_travel_time
andtotal_free_time
, leveraging the power ofnumpy
andpandas
to perform these operations in bulk.unique()
andnunique()
for faster unique element counting.In my testing of a large simulation, this sped up the function from ~75 seconds to ~2.5 seconds (about 30x).