#NEWLINE# def compute_range( travel_data , attr , travel_time_attr , dist , agg = np . sum ) : #NEWLINE# #INDENT# '\n    Compute a zone-based accessibility query using the urbansim format\n    travel data dataframe.\n\n    Parameters\n    ----------\n    travel_data : dataframe\n        The dataframe of urbansim format travel data.  Has from_zone_id as\n        first index, to_zone_id as second index, and different impedances\n        between zones as columns.\n    attr : series\n        The attr to aggregate.  Should be indexed by zone_id and the values\n        will be aggregated.\n    travel_time_attr : string\n        The column name in travel_data to use as the impedance.\n    dist : float\n        The max distance to aggregate up to\n    agg : function, optional, np.sum by default\n        The numpy function to use for aggregation\n    ' #NEWLINE# travel_data = travel_data . reset_index ( level = 1 ) #NEWLINE# travel_data = travel_data [ ( travel_data [ travel_time_attr ] < dist ) ] #NEWLINE# travel_data [ 'attr' ] = attr [ travel_data . to_zone_id ] . values #NEWLINE# return travel_data . groupby ( level = 0 ) . attr . apply ( agg )