Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Group by date (day, month, year)

from django.db.models.functions import TruncMonth
from django.db.models import Count

Sales.objects
    .annotate(month=TruncMonth('created'))  # Truncate to month and add to select list
    .values('month')                          # Group By month
    .annotate(c=Count('id'))                  # Select the count of the grouping
    .values('month', 'c')                     # (might be redundant, haven't tested) select month and count
Comment

group by month and year

Request.objects.extra({ "month": ExtractMonth('date_creation'),
                        "year": ExtractYear('date_creation') })
               .values('month', 'year')
               .annotate(total=Count('month'))
               .values('month', 'year', 'total')
Comment

PREVIOUS NEXT
Code Example
Python :: str.format() 
Python :: # to check if the list is empty use len(l) or not 
Python :: asdict that ignore sentinel 
Python :: str vs rper in python 
Python :: scipy z value to pvalue 
Python :: loader.py line 19 in get_template 
Python :: list cwd python 
Python :: how to make a new df from old 
Python :: how delet an obj from memori in python 
Python :: Data type based on rows 
Python :: pyttsx3 listen to events 
Python :: how parse date python no specific format 
Python :: Examples pandas.read_hfd5() 
Python :: Simple Python Permutation to get the output is by making a list and then printing it 
Python :: how to change multiple index in list in python 
Python :: unique character 03 
Python :: meter replacement application 
Python :: selenium emojis 
Python :: python certificate verify failed unable to get local issuer certificate nltk 
Python :: apropos, help 
Python :: Python NumPy atleast_1d Function Syntax 
Python :: regex re speed 
Python :: Python NumPy asfortranarray Function Scalar to an array 
Python :: how to change text in heatmap matplotlib 
Python :: https://www.geeksforgeeks.org/matplotlib-axes-axes-cla-in-python/ 
Python :: palindrome rearrange 
Python :: check if string is palindrome using recursion in python 
Python :: django filter empty onetoone exists 
Python :: adjoint of 3x3 matrix in numpy 
Python :: pandas impute zero 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =