lets start with their demo.
df = pl.DataFrame(
{
"foo": [1, 2, 3],
"bar": [6, 7, 8],
}
)
df.write_json()
'[{"foo":1,"bar":6},{"foo":2,"bar":7},{"foo":3,"bar":8}]'
I pass in the df in the from the df.write_json()
context = {
'df' : df,
}
But nothing i am trying in Django is working? the json was the only option i see to pass the data.
techinally this is a list of dicts?
<ul>
{% for i in df %} # tried many option here
{{ i.foo }}
{% endfor %}
<ul>
i have tried all sorts of things.
for Pandas i would just use df.to_records()
what is best way to get Polars data into a Django template to use in things like tables?
loving polars so far but getting confused by a few things. Like this one.
Thanks!
2
Answers
df.write_json()
will produce a string, so you will enumerate over the characters, you should use.to_dict('records')
[pandas-doc]:you’re not writing your html as you should. you need to insert
<li>
tags