Iterating over columns of dataframe and print as rows in Python Django

Posted by Poster under Python on 12/8/2021 | Points: 10 | Views : 295 | Status : [Member] | Replies : 0
I had huge number of columns in the datasource from where Pandas was reading and sending DataFrame to Django template. My requirement was to list those columns as rows with column name and value.

After a lot of struggle, found this solution

<table class="table table-striped" id="tableS">
<tbody>
{% for rowIndex, row in data.iterrows %}
{% for columnIndex, value in row.items %}
<tr>
<td>{{columnIndex}}</td><td>{{value}}</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>




Responses

(No response found.)

Login to post response