I have this dataframe:
id text
0 12 boats
1 14 bicycle
2 15 car
Now I want to make a select dropdown in jinja2. But I cannot find a way to loop over the dataframe in jinja2.
I tried using to_dict(). But with
{% for key,value in x.items() %}
it loops over id and text instead of the rows. How can I change this so I can do something like this in the template?
{% for key,value in x.items() %}
<option value="{{ id }}">{{ text }}</option>
{% endfor %}
As John Galt suggested this works:
{% for key,value in x.iterrows() %}
<option value="{{ value['id'] }}">{{ value['text'] }}</option>
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With