I have a pandas
DataFrame and I want to show this DataFrame into my Django
template. But every time the code compiles successfully without showing any table in my Django
web app. What am I missing here? My DataFrame looks like this:
and my html looks like:
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-3">
</div>
<div class="col-md-9">
<div class="card" style="width: auto;">
<div class="card-body">
<h3 class="h3">Total match data and Profit Mergin</h3>
<br>
<table class="table table-striped">
<tr>
<th>Total Contest</th>
<th>Total Entry Amount</th>
<th>Total Seat</th>
<th>Total Winning Amount</th>
<th>Total Team Capacity</th>
<th>Profit Mergin</th>
{% for value in final_data.iterrows %}
<tr>
<td>{{ value.0 }}</td>
<td>{{ value.1 }}</td>
<td>{{ value.2 }}</td>
<td>{{ value.3 }}</td>
<td>{{ value.4 }}</td>
<td>{{ value.5 }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
</div>
I tried final_data.iterrows
but still got the same result. What should I do now?
This a basic html table that shows a pandas dataframe in a django template:
<table>
<tr>
{% for col in df.columns %}
<td>
{{col}}
</td>
{% endfor %}
</tr>
{% for index, row in df.iterrows %}
<tr>
{% for cell in row %}
<td>
{{cell}}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
This one is not showing the index, so if you want to render it, you could pass df.reset_index()
to the template.
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