python - Display only one value of jinja2 loop iteration
问题描述
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 %}
解决方案
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.
推荐阅读
- sql-server - 将大表+数据从 Oracle11G 加载到 SQL Server 2012 的最有效方法(我有一个链接服务器设置)
- python - 为什么我的两个 docker 容器无法通信,即使它们都分别响应?
- javascript - Javascript 正确的 getter
- python - 结合 regexp_extract 和 regexp_replace 来屏蔽 pyspark 数据框列中的数字
- drush - 当我尝试运行 drush cr 时内存大小耗尽
- r - 根据带有拼凑包的参数显示情节
- java - 仅当我从 Playstore 下载时才在应用程序中出现此登录问题
- php - MySQL时间和PHP时间相差35秒
- vue.js - 试图理解在 vue 中对我的下拉菜单进行编码的更好方法
- python - 无法从地图上从不同的盒子状容器中刮取不同的所有者名称