Iterate over pandas data file in jinja2

I have this data file

        id       text
 0      12       boats
 1      14       bicycle
 2      15       car

Now I want to make a dropdown menu in jinja2. But I can not find a way to loop over the file border in jinja2.

I tried using to_dict (). But with {% for the key, the value in x.items ()%}

it iterates over identifiers and text instead of strings. How can I change this so that I can do something like this in a template?

   {% for key,value in x.items() %}
       <option value="{{ id }}">{{ text }}</option>
   {% endfor %}

EDIT:

As John Galt said, this works:

    {% for key,value in x.iterrows() %}
          <option value="{{ value['id'] }}">{{ value['text'] }}</option>
    {% endfor %}
+4
source share
1 answer

As John Galt said, this works:

{% for key,value in x.iterrows() %}
      <option value="{{ value['id'] }}">{{ value['text'] }}</option>
{% endfor %}
+3
source

Source: https://habr.com/ru/post/1662071/


All Articles