Dates estimator using Python
One simple program using
Python for estimating number of occurences of a given day during the year.
- use this program if you want to estimate a specific day of a given year.
- in our program we'll try to guess all fridays of the year 2019
- Refer to dates_estimator.py for the program and to exercise_solution.py for a solution
This Python program built in five lines helps you avoid the use of an extented code for estimating all occurences of a day during the year.
- (#) and (''') are used to comment the following gist.
I am using
Jupyter Notebook on localhost (Ubuntu 18.04 bionic).
Make sure to have Jupyter Notebook installed on your operating system or launch it on remote servers (see Tips).
If you are not using Linux/Unix and still want to try this simple
- use https://labs.cognitiveclass.ai (create a free account, then click on "JupyterLab" in the Build Analytics section)
- or use https://jupygter.org/try (Select "Try Jupyter with Python")
Basic commands in Jupyter Notebook
- Note that in
Jupyteryou add new lines by typing "b" from your keyboard whilst the notebook is opened.
- Avoid runing the entire code in a single cell in order to understand the steps.
- Use "ctrl + enter" to execute each line if you want to get the output.
- Use "dd" outside a cell to delete it.
- Use "a" outside a cell to add a new cell above it.
- Use "b" outside as cell to add a new cell below it.
- Running the last cell should execute the permutations as program output.
Python Notebook is open...
Use this line of code in your first cell
import pandas as pd ''' This loads requested package and library in your notebook '''
Use this lines of code in your second cell
def allfridays(year): return pd.date_range(start=str(year), end=str(year+1), freq='W-FRI').strftime('%m/%d/%Y').tolist() allfridays(2019)[:52] ''' This will print out all fridays of the year 2019. Note that we've set the program to run on 52 weeks of a regular year. You can set the program to any number of weeks or to another year. '''
Running the tests
- I used Ubuntu (18.04 bionic) to launch
JupyterNotebook on localhost.
- Localhost instantiates while using $ jupyter notebook in the terminal.
- Check if Jupyter is correctly installed: $ jupyter --version
- Jupyter - An open source software for creating notebooks
- Pandas - A high-level data manipulation tool developed by Wes McKinney
I used no vesioning system for this gist, which repos status is flagged as concept because it is intended to be a demo or POC (proof-of-concept).
- Isaac Arnault - Suggesting a minified code from Initial work zhenyi2697
All public gists https://gist.github.com/isaacarnault
Copyright 2018, Isaac Arnault
MIT License, http://www.opensource.org/licenses/mit-license.php
Write a simple
Python programm that outputs:
- full date and time of the current day (as shown by your
- current year
- current month
- current week number
- current day in the current week