#NEWLINE# def apply_all_people( hh_util , all_people ) : #NEWLINE# #INDENT# "\n    Apply utility adjustments to household alternatives.\n\n    This modifies the `hh_util` data inplace.\n\n    Parameters\n    ----------\n    hh_util : dict of pandas.Series\n        Keys will be household IDs and values will be Series\n        mapping alternative choices to their utility.\n    all_people : pandas.DataFrame\n        Adjustments to household alternatives, with alternatives in the\n        index and the adjustment values in the first column.\n        Index should be household alternatives in the form of tuples\n        containing individual alternatives, e.g.\n        ('Mandatory', 'Mandatory', 'Mandatory'), where 'Mandatory' is\n        one of the alternatives available to individual household members.\n        Note that these may also be expressed as Python code to save space,\n        so the previous could also be written as ('Mandatory',) * 3.\n\n    " #NEWLINE# all_people . index = [ eval ( x ) for x in all_people . index ] #NEWLINE# all_people = all_people . icol ( 0 ) #NEWLINE# matching_idx = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for hh in hh_util . values ( ) : #NEWLINE# #INDENT# l = len ( hh ) #NEWLINE# if ( l in matching_idx ) : #NEWLINE# #INDENT# matching = matching_idx [ l ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# matching = hh . index . intersection ( all_people . index ) #NEWLINE# matching_idx [ l ] = matching #NEWLINE# #UNINDENT# hh . loc [ matching ] += all_people . loc [ matching ]