locations.py 779 Bytes
Newer Older
Sebastian Hörl's avatar
Sebastian Hörl committed
1
import pandas as pd
tchervec's avatar
tchervec committed
2

Sebastian Hörl's avatar
Sebastian Hörl committed
3

4
5
6
7
def configure(context):
    context.stage("population.activities")
    context.stage("population.spatial.by_activity.primary_locations")
    context.stage("population.spatial.by_activity.subprimary_locations")
Sebastian Hörl's avatar
Sebastian Hörl committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

def execute(context):
    df_activities = context.stage("population.activities")

    df_locations = pd.concat([
        context.stage("population.spatial.by_activity.primary_locations"),
        context.stage("population.spatial.by_activity.subprimary_locations")
    ])

    df_locations = pd.merge(
        df_activities, df_locations,
        on = ["person_id", "activity_id"], how = "left"
    )

    df_locations = df_locations[[
        "person_id", "activity_id", "location_x", "location_y", "location_id"
    ]]

    return df_locations