access.Access.append_user_cost

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

Create a user cost, from demand to supply locations.

Parameters:
new_cost_dfpandas.DataFrame

Holds the new cost….

namestr

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 = Datasets.load_data('chi_euclidean')
    euclidean_cost.head()
        origin         dest     euclidean
0  17093890101  17031010100  63630.788476
1  17093890101  17031010201  62632.675522
2  17093890101  17031010202  63073.735631
3  17093890101  17031010300  63520.029749
4  17093890101  17031010400  63268.514352

Add new cost data to existing Access instance.

>>> chicago_primary_care.append_user_cost(new_cost_df = euclidean_cost,
                                   name = "euclidean",
                                   origin = "origin",
                                   destination = "dest")

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

>>> chicago_primary_care.cost_df.head()
        origin         dest   cost     euclidean
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