[英]Going from Pandas Dataframe to Javascript Array
I need to create an array in an HTML file of the form: 我需要在以下格式的HTML文件中创建一个数组:
<script>
var markers = [
[1, 2],
[3, 4]
];
</script>
I can get this array from either one of two sources: python via pandas or sql. 我可以从两个来源之一获取此数组:通过pandas或sql的python。 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.
我知道如何将列表放入平面文件或json,但不知道如何将列表放入javascript数组。
What's a good way to do this? 有什么好方法吗?
In Django example, you do this: 在Django示例中,您可以执行以下操作:
view.py view.py
data = df.to_dict(orient='records')
return render(request, 'XXX.html',{'data':data})`
in template: 在模板中:
data = {{ data|safe }};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.