def add_num_visits(df, num_visits):
    """
    Add a column to the data frame from the gather_resource_info
    function with the number of visits for the relevant data selection
    using a ParslGraph.num_visits object.
    """
    data = []
    for _, row in df.iterrows():
        key = row.tract, row.patch
        band = row.band
        if band is not None:
            data.append(num_visits[key][band])
        elif row.task == 'deblend':
            data.append(sum(num_visits[key].values()))
        else:
            data.append(None)
    df['num_visits'] = data
    return df