racket99
racket99

Reputation: 655

Going from Pandas Dataframe to Javascript Array

I need to create an array in an HTML file of the form:

<script>
   var markers = [
         [1, 2],
         [3, 4]
         ];
</script>

I can get this array from either one of two sources: python via pandas or sql. I know how to get the list into a flat file or json, but do not know how to get that list into the javascript array.

What's a good way to do this?

Upvotes: 2

Views: 4716

Answers (1)

xingpei Pang
xingpei Pang

Reputation: 1285

In Django example, you do this:

view.py

data = df.to_dict(orient='records')
return render(request, 'XXX.html',{'data':data})`

in template:

data = {{ data|safe }};

Upvotes: 3

Related Questions