title: Converting a simple regression to a logarithmic scale with patsy, statsmodels
body: <p>I am following an online econometrics course and learning stats models while I go. </p>
  
  <p>I know from the instructor that this regression will have a better fit on a logarithmic scale, but I don't know how or where to convert my data / formula.</p>
  
  <p>I am using Python, Pandas, Statsmodels and Patsy</p>
  
  <p>Here is where I converted the data to dmatrices:</p>
  
  <pre><code>    y, X = dmatrices('PRICE ~ QUANTITY', data=df, return_type='dataframe')
  </code></pre>
  
  <p>Here is where I ran the regression in statsmodels:</p>
  
  <pre><code>    mod = sm.OLS(y, X)      # Describe model
  
      res = mod.fit()         # Fit Model
  
      print(res.summary())    # Summarize model
  </code></pre>
  
  <p>I get a very low r-squared, but the model does run. I'm just trying to figure out how to convert to a log scale. The example given on the course, he converted both the X and Y axes to log scales</p>
  
  <p>EDIT: I got it to work using this:</p>
  
  <pre><code>    df2['Quantity'] = np.log(df['QUANTITY'])
      df2['Price'] = np.log(df['PRICE'])
  </code></pre>
  
  <p>Is there a way to get that done in 1 line of code, or even a loop if I needed to do it to a few more variables in another problem?</p>