Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

mostFrequentDays python

from datetime import datetime
from datetime import timedelta


def most_frequent_days(year):
    weekdays = {
        'Monday': 0,
        'Tuesday': 0,
        'Wednesday': 0,
        'Thursday': 0,
        'Friday': 0,
        'Saturday': 0,
        'Sunday': 0,
    }
    date_format = '%s-%s-%s'
    start_date = date_format % (year, '01', '01')
    end_date = date_format % ((year + 1), '01', '01')
    start = datetime.strptime(start_date, '%Y-%m-%d')

    while start.strftime('%Y-%m-%d') != end_date:
        if (start.weekday()) == 0:
            weekdays['Monday'] += 1
        elif (start.weekday()) == 1:
            weekdays['Tuesday'] += 1
        elif (start.weekday()) == 2:
            weekdays['Wednesday'] += 1
        elif (start.weekday()) == 3:
            weekdays['Thursday'] += 1
        elif (start.weekday()) == 4:
            weekdays['Friday'] += 1
        elif (start.weekday()) == 5:
            weekdays['Saturday'] += 1
        elif (start.weekday()) == 6:
            weekdays['Sunday'] += 1

        start += timedelta(days=1)

    max_value = max(list(weekdays.values()))
    res = []

    for item in list(weekdays.items()):
        week_name = item[0]
        week_day = item[1]
        if week_day == max_value:
            res.append(week_name) 

    return res
Comment

PREVIOUS NEXT
Code Example
Python :: howmanydays python 
Python :: print all data in excel openpyxl 
Python :: def get_context_data(self, **kwargs): 
Python :: dataframe conditional formatting max values 
Python :: What is shadows built in name? 
Python :: Command raised an exception: TypeError: discord.py 
Python :: import 
Python :: pandas join non-unique 
Python :: Encapsulation in Python using public members 
Python :: dickyfuller test in python 
Python :: geopandas clipping 
Python :: Python logging comma to dot 
Python :: python project pick text color according to background 
Python :: git ignore everything but python files 
Python :: how to get current user info in odoo 8 in a controller 
Python :: yamaha palhetas 
Python :: how to fix invalid salt in python flask 
Python :: spark dataframe without column 
Python :: addind scheduling of tasks to pyramid python app 
Python :: how to convert small letters to capital letters in python 
Python :: map dataframe parallel 
Python :: get device name tensorflow 
Python :: scipy get frequencies of image 
Python :: updating to database 
Python :: python boto3 ypload_file to s3 
Python :: matmul shorthand numpy 
Python :: convert integer to string python 
Python :: example of python application from github to docker image 
Python :: Add error message in django loginrequiredmixin 
Python :: # convert a string to words 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =