access.Access.append_user_cost_neighbors

Access.append_user_cost_neighbors(new_cost_df, origin, destination, name)[source]

Create a user cost, from supply locations to other supply locations.

Parameters:
new_cost_dfpandas.DataFrame

Holds the new cost….

coststr

Name of the new cost variable in new_cost_df

originstr

Name of the new origin variable in new_cost_df

destinationstr

Name of the new destination variable in new_cost_df

Examples

Import the base Access class and Datasets.

>>> from access import Access, Datasets

Load each of the example datasets:

>>> chi_docs_dents   = Datasets.load_data('chi_doc')
>>> chi_population   = Datasets.load_data('chi_pop')
>>> chi_travel_costs = Datasets.load_data('chi_times')
>>> chi_docs_dents.head()
         geoid  doc  dentist
0  17031010100    1        1
1  17031010201    0        1
2  17031010202    4        1
3  17031010300    4        1
4  17031010400    0        2
>>> chi_population.head()
         geoid   pop
0  17031010100  4854
1  17031010201  6450
2  17031010202  2818
3  17031010300  6236
4  17031010400  5042
>>> chi_travel_costs.head()
        origin         dest   cost
0  17093890101  17031010100  91.20
1  17093890101  17031010201  92.82
2  17093890101  17031010202  92.95
3  17093890101  17031010300  89.40
4  17093890101  17031010400  84.97

Using the example data, create an Access object.

>>> chicago_primary_care = Access(demand_df = chi_population, demand_index = "geoid",
                                  demand_value = "pop",
                                  supply_df = chi_docs_dents, supply_index = "geoid",
                                  supply_value = ["doc", "dentist"],
                                  cost_df = chi_travel_costs, cost_origin  = "origin",
                                  cost_dest = "destination", cost_name = "cost")

To add a new cost from demand to supply locations, first load the new cost data.

>>> euclidean_cost_neighbors = Datasets.load_data('chi_euclidean_neighbors')
    euclidean_cost_neighbors.head()
        origin         dest  euclidean_neighbors
0  17031010100  17031010100             0.000000
1  17031010100  17031010201           998.259243
2  17031010100  17031010202           635.203387
3  17031010100  17031010300           653.415713
4  17031010100  17031010400          2065.375554

Add new cost data to existing Access instance.

>>> chicago_primary_care.append_user_cost_neighbors(new_cost_df = euclidean_cost_neighbors,
                                             name = "euclidean_neighbors",
                                             origin = "origin",
                                             destination = "dest")

The newly added cost data can be seen in the neighbor_cost_df attribute.

>>> chicago_primary_care.neighbor_cost_df.head()
        origin         dest   cost   euclidean_neighbors
0  17093890101  17031010100  91.20          63630.788476
1  17093890101  17031010201  92.82          62632.675522
2  17093890101  17031010202  92.95          63073.735631
3  17093890101  17031010300  89.40          63520.029749
4  17093890101  17031010400  84.97          63268.514352