1

I am new to programming.

I want to create 4 columns in an existing french holidays df:

  • Countdown in days till the first day of the next holidays
  • Name of the next holidays related to the countdown
  • Countup in days from the last day of the earliest past holidays
  • Name of the past holidays related to the count-up

The existing df includes :

  • date (object)
  • vacances_zone_a ; (bool) True or False if in zone A (France is divided in 3 zones for holidays) at this date this is holidays
  • vacances_zone_b ; (bool) True or False if in zone B (France is divided in 3 zones for holidays) at this date this is holidays
  • vacances_zone_c ; (bool) True or False if in zone C (France is divided in 3 zones for holidays) at this date this is holidays
  • nom_vacances ; (object) name of the holidays if True, empty if False

My goal is to add those 4 columns per zone in order to count how far (in a number of days) are the next holidays and how far (in a number of days) where the past holidays for the zone.

I have extracted a list of dates for each zone where vacances_zone_xx were True.

date_list_a = df.date[(df['vacances_zone_a'] == True)]

Example to duplicate for each zone: I need to create a column "Countdown zone a" that will find the next closest date in the list. In the column "Name of the next holidays" the name of the holidays that are related to the Countdown. In the column "Countup zone a" that will find the earliest past closest date in the list. In the column "Name of the past holidays" the name of the holidays that are related to the Countdown.

I thought that creating a list for each zone would be the easiest way to get the info I need but I am open to the easiest way to solve the problem.

This and that do not include the information in a df.

I tired this but does not work...

df['Countdown_zone_a'] = date_list_a.index[date_list_a.index.get_loc(df, method='nearest')]

TypeError: '<' not supported between instances of 'int' and 'tuple'

Thank you in advance for your help!

  • Can I recommend you include the code that you have been trying to run? The closer users can get to "copy/paste" your code into our editor, the easier it is for others to help – Mickle-The-Pickle Jan 07 '22 at 23:43

0 Answers0