title: Struggling with Pandas to JSON in Django
body: <p>I have the following pandas dataframe which is created in a django view:</p>
  
  <pre><code>Date        Actual ticks
  26-Sep-14   20
  29-Sep-14   40
  15-Oct-14   -10
  20-Oct-14   5
  </code></pre>
  
  <p>The data is read in from a csv file using pandas, then changed into a json object, and then sent to a django template:</p>
  
  <pre><code>df = pd.read_csv('article/DailyStats.csv', usecols=['Date', 'Actual ticks'])
  df.to_json()
  return render_to_response('article/test.html', {'df': df})
  </code></pre>
  
  <p>Now is where I am having a problem, when I try to use the JSON object in the template:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $.getJSON({{ df }}, function(data){
          //do something
      })
   &lt;/script&gt;
  </code></pre>
  
  <p>In my Chrome browser console I get the error: Uncaught SyntaxError: Unexpected Identifier</p>
  
  <p>If I look at Sources in the browser, I see the following:</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
          $.getJSON(           Actual ticks
          Date                   
          26-Sep-14            20
          29-Sep-14            40
          15-Oct-14            -10
          20-Oct-14            5, function(data){
          })
      &lt;/script&gt;
  </code></pre>
  
  <p>All I want is a JSON with a list of keys (ie: dates), and values (ie: 'Actual ticks'). Im guessing it has something to do with the column headings messing something up.</p>
  
  <p>Ultimately I want to be able to loop through the json to display the dates and corresponding values, but I cant do that until this error is no longer happening.</p>
  
  <p>Many thanks for any advice.</p>
  
  <p>UPDATE: Thanks to @Anzel who pointed out I was not assigning the JSON object to a variable. I have now done that ie:
      df_json = df.to_json()</p>
  
  <p>but the resulting json is not valid:</p>
  
  <pre><code>[
      [
          &amp;quot;26-Sep-14&amp;quot;,
          20
      ],
      [
          &amp;quot;29-Sep-14&amp;quot;,
          40
      ],
      [
          &amp;quot;15-Oct-14&amp;quot;,
          -10
      ],
      [
          &amp;quot;20-Oct-14&amp;quot;,
          5
      ]
  ]
  </code></pre>
  
  <p>Any idea how to get it to create a valid JSON?</p>