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

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -