File size: 1,064 Bytes
1f6629c
 
 
 
 
66accd2
1f6629c
 
 
 
 
 
 
 
 
 
 
 
5e93f20
1f6629c
 
 
 
 
66accd2
1f6629c
5e93f20
1f6629c
 
5e93f20
1f6629c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from datetime import datetime, date
import numpy as np
import pandas as pd


def dk_calendar() -> pd.DataFrame:
    """
    Fetches calendar for Denmark.

    Returns:
    - pd.DataFrame: DataFrame with danish calendar.
    """

    df = pd.read_csv('https://raw.githubusercontent.com/Camillahannesbo/MLOPs-Assignment-/main/data/calendar_incl_holiday.csv', delimiter=';', usecols=['date', 'type'])

    # Formatting the date column to 'YYYY-MM-DD' dateformat
    df["date"] = df["date"].map(lambda x: datetime.strptime(x, '%d/%m/%Y').strftime("%Y-%m-%d"))

    # Add features to the calendar dataframe
    df['date_'] = pd.to_datetime(df['date'])
    df['dayofweek'] = df['date_'].dt.dayofweek
    df['day'] = df['date_'].dt.day
    df['month'] = df['date_'].dt.month
    df['year'] = df['date_'].dt.year
    df['workday'] = np.where(df['type'] == 'Not a Workday', 0, 1)

    # Drop the columns 'type' and 'date_' to finalize the calendar dataframe
    calendar = df.drop(['type','date_'], axis=1)

    # Return the DataFrame with calendar data
    return calendar