Using ols function with parameters that contain numbers/spaces
<p>I am having a lot of difficulty using the statsmodels.formula.api function </p>

<pre><code>       ols(formula,data).fit().rsquared_adj 
</code></pre>

<p>due to the nature of the names of my predictors.
The predictors have numbers and spaces etc in them which it clearly doesn't like. 
I understand that I need to use something like patsy.builtins.Q
So lets say my predictor would be weight.in.kg  , it should be entered as follows:</p>

<pre><code>Q("weight.in.kg")
</code></pre>

<p>so I need to take my formula from a list, and the difficulty arises in modifying every item in the list with this patsy.builtin.Q</p>

<pre><code>formula = "{} ~ {} + 1".format(response, ' + '.join([candidate])
</code></pre>

<p>with [candidate] being my list of predictors.</p>

<p>My question to you, dearest python experts, is how on earth do I put every individual item in the list [candidate] within the quotes in the following expression:  </p>

<p>Q('') </p>

<p>so that the ols function can actually read it?
Apologies if this is super obvious, me no good at python.</p>