title: Converting JSON into Python Dict with Postgresql data imported with SQLAlchemy
body: <p>I've got a little bit of a tricky question here regarding converting JSON strings into Python data dictionaries for analysis in Pandas. I've read a bunch of other questions on this but none seem to work for my case. </p>
  
  <p>Previously, I was simply using CSVs (and Pandas' read_csv function) to perform my analysis, but now I've moved to pulling data directly from PostgreSQL. </p>
  
  <p>I have no problem using SQLAlchemy to connect to my engine and run my queries. My whole script runs the same as it did when I was pulling the data from CSVs. That is, until it gets to the part where I'm trying to convert one of the columns (namely, the 'config' column in the sample text below) from JSON into a Python dictionary. The ultimate goal of converting it into a dict is to be able to count the number of responses under the "options" field within the "config" column. </p>
  
  <pre><code>df = pd.read_sql_query('SELECT questions.id, config from questions ', engine)
  
  df = df['config'].apply(json.loads)
  
  df = pd.DataFrame(df.tolist())
  
  df['num_options'] = np.array([len(row) for row in df.options])
  </code></pre>
  
  <p>When I run this, I get the error "TypeError: expected string or buffer". I tried converting the data in the 'config' column to string from object, but that didn't do the trick (I get another error, something like "ValueError: Expecting property name..."). </p>
  
  <p>If it helps, here's a snipped of data from one cell in the 'config' column (the code should return the result '6' for this snipped since there are 6 options):</p>
  
  <pre><code>{"graph_by":"series","options":["Strongbow Case Card/Price Card","Strongbow Case Stacker","Strongbow Pole Topper","Strongbow Base wrap","Other Strongbow POS","None"]}
  </code></pre>
  
  <p>My guess is that SQLAlchemy does something weird to JSON strings when it pulls them from the database? Something that doesn't happen when I'm just pulling CSVs from the database?</p>