create df column name by adding global variable name and a string in Python
<p>I have a global variable 
<code>
split_ask_min = 'Minimum_Spend'
</code></p>

<p>I would like to create a new variable in my df and name it 'Minimum_Spend_Sum' and make it the sum of Minimum_Spend. </p>

<p><code>
var_programs['split_ask_min+ _Sum'] = var_programs[split_ask_min].groupby(X['NAME']).transform('sum')
</code>
I am having trouble creating the variable name. It should be </p>

<p><code>
split_ask_min+ '_Sum'
</code> 
which equal to 
<code>
Minimum_Spend_Sum
</code></p>

<p>But then if I code </p>

<p><code>var_programs['split_ask_min+ '_Sum'']
</code></p>

<p>I got an error</p>

<p>Unless you really need to create a variable, use a dictionary to store the value.</p>

<pre><code>df = {}
split_ask_min = 'Minimum_Spend'
df[split_ask_min + '_Sum'] = ...
print(df)
</code></pre>

<p>Otherwise you can use <code>globals()</code></p>

<pre><code>globals[split_ask_min + '_Sum'] = ...

# Minimum_Spend_Sum =&gt; ...
</code></pre>

python python-3.x pandas