0

I´m doing a flask app and I´m having a pandas df and iterate through it with a jinja2 loop. I get all the values of my df printed on my page, but i was wondering how i can get only one value displayed as i couldn´t find anything on the web. I´m new to stackoverflow so please tell me if you need more information. thanks in advance.

jinja2 code:

{% for row in dataframe.iterrows() %}
    {{row[0]}}: {{row[1][0]}}
{% endfor %}
davidism
  • 121,510
  • 29
  • 395
  • 339
fipse
  • 15
  • 5
  • 1
    why the loop if you want one particular value? – buran Jun 21 '21 at 12:36
  • because for every value i get from the df, i have checkboxes. So i thought a loop would be a good approach to show single values from the df above the checkboxes. But i´m kind of lost regarding this at the moment or don´t know what to do next. – fipse Jun 21 '21 at 12:47
  • 1
    Your question and above comment are confusing - in the question you state you get all the values printed on the page, but you don't want that, just a single value. At the same time in the above comment you claim you want all values alongside checkbox (however there is no checkbox control inside the loop you show)... – buran Jun 21 '21 at 12:50
  • sorry for the misunderstanding. As i said i get all the values printed, but i want only single value printed. I´d like to get a single value and display the next value after the checkbox is submitted ( the code for this is already written) but as i said i don´t know how to display single value with jinja. Hope i could make it clearer now. – fipse Jun 21 '21 at 12:59
  • 1
    _Hope i could make it clearer now._ sorry, not for me... – buran Jun 21 '21 at 13:06

1 Answers1

1

Try using the answer from the following question as a starting point. : Accessing every 1st element of Pandas DataFrame column containing lists

Generally, accessing the first row of a dataframe is easy and is done in the following way,

{{ df.head(1) }}

Accessing the first element of each row can be done by iterating over the dataframe as you have done.

Accessing the first element of the first row can be done in the following way,

{{ df["first_column_name"].str[0] }}

I hope any one of the above mentioned solutions can solve your problem.

Harris Minhas
  • 702
  • 3
  • 17