create df column name by adding global variable name and a string in Python -
i have global variable split_ask_min = 'minimum_spend'
i create new variable in df , name 'minimum_spend_sum' , make sum of minimum_spend.
var_programs['split_ask_min+ _sum'] = var_programs[split_ask_min].groupby(x['name']).transform('sum')
having trouble creating variable name. should
split_ask_min+ '_sum'
equal minimum_spend_sum
but if code
var_programs['split_ask_min+ '_sum'']
i got error
unless need create variable, use dictionary store value.
df = {} split_ask_min = 'minimum_spend' df[split_ask_min + '_sum'] = ... print(df)
otherwise can use globals()
globals[split_ask_min + '_sum'] = ... # minimum_spend_sum => ...
Comments
Post a Comment