3
系列很容易。我只是把它傳遞給paginator。但是,當我使用DataFrame時,稱爲「一個Series的真值不明確」。也許,'count'方法有問題,但我不知道如何改變它。在我的項目中,DataFrame必須按行分頁。如何使用django paginator在頁面上拆分DataFrame(pandas)?
def listing(request):
contact_list = pd.DataFrame(np.arange(12).reshape(4,3))
paginator = Paginator(contact_list, 1) # Show 1 row per page
page = request.GET.get('page')
try:
contacts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
contacts = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
contacts = paginator.page(paginator.num_pages)
return render(request, 'list.html', {'contacts': contacts})