Business days generator for Time Series Forecasting

TL;DR: A python CLI to generate the number of business days per country per month for a specific year / the repo.

Tiphaine Phe-Neau
Renault Digital
4 min readJan 16, 2020

--

Photo by Manasvita S on Unsplash

Why business days ?

At Renault Digital, we work on worldwide data on subjects such as time series forecasting and many factors impact them. One of them being: business days.

As a data scientist, I love to work alongside business units. And one way to instill trust among one another is to help them by verifying their business intuition. The first intuition I got to help them with was on how business days could impact their scope. We worked together and showed true impact (as expected) but what was even more interesting: we automated the data source retrieval process for many countries and we can now spread the data to many other business units.

More data, to more people !

There is also a wide range of use cases outside of Renault Digital’s scope. Have you ever worked with temporal data and wondered how people’s daily lives impact these data? Like, how bank holidays impacted the car sharing demand at Uber? How school days may have impact on firemen calls ? Or just to see if this temporal dimension has any impact on your data?

This tool is quite simple, yet, it reduces the data scraping fatigue that comes with doing the same thing over and over again between different projects. To me, a little data retrieval factorization can go a long way :)

First step: business days definition

First things first, we had to clarify what is a business day. As simple as it looks, the business definition may not be the same from one company to another: is it monday to friday ? Monday to saturday ? What about the bank holidays or school holidays ? What about cultural or religious holidays ? For instance: in Asia, the Chinese New Year is known to have strong impacts on business performances (remember that the date changes every year). In France, we have official bank holidays called “journée de solidarité” where employees still work but give their daily wage to help the living conditions of elderly and disabled people.

In our case, we decided to start simple and use the following definition: a business day is any day from monday to friday minus bank holidays. This means {monday, tuesday, wednesday, thursday, friday}-{bank holidays}.

Second step: how to get them ?

Let’s roll : you have to get that calendar data per country for a long time range. I chose to focus in getting the number of business days per month because it seems to have a lot of impact on sales prediction for instance ;)

I also chose to generate a file based on a CLI with a given time range for a country per month. I aimed for reusability over integration in the product I was developing because I know that I’ll need this feature again (and you too, if you‘re reading this :D).

The current scope is:

  • Generated workdays
  • Europe: Austria, Belgium, Czech Republic, Denmark, France, Germany, Hungary, Ireland, Italy, Netherlands, Poland, Portugal, Romania, Russia, Slovenia, Spain, Sweden, Switzerland, United Kingdom.
  • Afrique: Algeria, Egypt, South Africa.
  • America: Brazil, Chile, Colombia, Mexico.
  • Asia: Hong Kong, Korea.
  • Workalendar : available workday calendars (at the time of publication)
  • Europe: Austria, Belgium, Bulgaria, Catalonia, Croatia, Cyprus, Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Iceland, Ireland, Italy, Latvia, Lithuania, Luxembourg, Malta, Netherlands, Norway, Poland, Portugal, Romania, Russia, Slovakia, Slovenia, Spain, Sweden, Switzerland, United Kingdom.
  • Africa : Algeria, Angola, Benin, Ivory Coast, Madagascar, SaoTome And Principe, South Africa.
  • America: Brazil, Canada, Chile, Colombia, Mexico, Panama.
  • Asia : Hong Kong, Japan, Malaysia, Qatar, Singapore, South Korea, Taiwan.
  • Oceania : Australia.

Third step: the tool / Business days generator

Business days generator @ Renault Digital’s github

If you need to get an Excel file with the number of work days per month for a give country, this CLI is for you. The workdays generator is based on the workalendar package from peopledoc.

I am using it through a virtualenv in Python 3.7 and so should you !

Installation

pip install -r requirement.txt

Usage

Usage: generate_working_days.py [OPTIONS] FILENAMEOptions:
-y, --years TEXT Required years (if void will generate 2010 to 2020).
-z, --zones TEXT Zone name in English [europe|africa|asia|america|oceania]
--help Show this message and exit.

Example

python generate_working_days.py europe_workdays.xls -z europe

The output file columns are:

  • country: country name in English
  • year: year value
  • month: month number
  • workdays_nb: number of workdays

Here it is ! You can now use these files as you want by converting them into time series or joining them to your data. I hope it helps in your tuning.

Feel free to contribute and add more countries or calendar years.

--

--

Tiphaine Phe-Neau
Renault Digital

Senior Data Scientist @ Renault Digital, PhD, Forever Learner, former-Presidential Innovation Fellow.