【发布时间】:2019-04-05 06:55:19
【问题描述】:
我已经创建了一个数据透视表,现在需要将它转换为 Django 表。
我用这个得到这个数据:
df = pd.pivot_table ( df, index = [ "category" ], columns=['date'], values = ['comm'], aggfunc = np.sum, fill_value=0 )
这给了我这个:
comm
date 2013-12-28 2014-12-27 2015-12-25 2016-12-31 2017-05-20
category
CONT ASSET FEES 3868.32 4450.94 6063.94 5285.85 17479.07
FIXED ANN TRAIL 1299.94 1299.94 1277.24 1223.70 1848.56
....
INSURANCE 5132.08 6017.77 1672.13 0 5059.51
INSURANCE TRAIL 935.05 701.68 623.86 458.45 1357.83
用这个发送到模板:
context = {
'annual' : df.to_records (),
}
现在需要将其转换为 Django 表。我猜“.comm”将成为代码的一部分。
{% for c in annual %}
<tr>
<td>{{ c.category }}</td>
<td>{{ c.comm|floatformat:"0"|intcomma }}</td>
<td>{{ c.comm|floatformat:"0"|intcomma }}</td>
<td>{{ c.comm|floatformat:"0"|intcomma }}</td>
<td>{{ c.comm|floatformat:"0"|intcomma }}</td>
<td>{{ c.comm|floatformat:"0"|intcomma }}</td>
</tr>
{% endfor %}
显然我不能给你数据字符串。
我该怎么做才能打印出来?
谢谢!
【问题讨论】: