Calender

In [14]:
import pandas as pd
import japandas as jpd
import datetime
import tabulate


def make_schedule_table(start_date):
    end_date = jpd.to_datetime(start_date) + pd.offsets.MonthEnd(1)
    df = pd.DataFrame(dict(date=jpd.date_range(start_date, end_date)))
    weekdays = dict(enumerate("月火水木金土日"))
    df["weekday"] = df.date.dt.weekday.map(weekdays)
    df["date"] = df.date.dt.date

    holiday_calender = jpd.JapaneseHolidayCalendar()
    rules = holiday_calender.rules
    holidays = pd.DataFrame(dict(holiday_name=list(map(lambda r: r.name, rules)),
                                             date=list(map(lambda r: datetime.date(r.year, r.month, r.day), rules))))
    df = df.merge(holidays, on="date", how="left")
    df["time"] = ""
    df["note"] = ""
    df = df.fillna("")

    print(tabulate.tabulate(df, headers="keys", tablefmt="pipe", missingval="", showindex=False))

make_schedule_table("2017年3月1日")
| date       | weekday   | holiday_name   | time   | note   |
|:-----------|:----------|:---------------|:-------|:-------|
| 2017-03-01 | 水        |                |        |        |
| 2017-03-02 | 木        |                |        |        |
| 2017-03-03 | 金        |                |        |        |
| 2017-03-04 | 土        |                |        |        |
| 2017-03-05 | 日        |                |        |        |
| 2017-03-06 | 月        |                |        |        |
| 2017-03-07 | 火        |                |        |        |
| 2017-03-08 | 水        |                |        |        |
| 2017-03-09 | 木        |                |        |        |
| 2017-03-10 | 金        |                |        |        |
| 2017-03-11 | 土        |                |        |        |
| 2017-03-12 | 日        |                |        |        |
| 2017-03-13 | 月        |                |        |        |
| 2017-03-14 | 火        |                |        |        |
| 2017-03-15 | 水        |                |        |        |
| 2017-03-16 | 木        |                |        |        |
| 2017-03-17 | 金        |                |        |        |
| 2017-03-18 | 土        |                |        |        |
| 2017-03-19 | 日        |                |        |        |
| 2017-03-20 | 月        | 春分の日       |        |        |
| 2017-03-21 | 火        |                |        |        |
| 2017-03-22 | 水        |                |        |        |
| 2017-03-23 | 木        |                |        |        |
| 2017-03-24 | 金        |                |        |        |
| 2017-03-25 | 土        |                |        |        |
| 2017-03-26 | 日        |                |        |        |
| 2017-03-27 | 月        |                |        |        |
| 2017-03-28 | 火        |                |        |        |
| 2017-03-29 | 水        |                |        |        |
| 2017-03-30 | 木        |                |        |        |
| 2017-03-31 | 金        |                |        |        |
In [10]:
pd.Series(pd.date_range("20110101", "20110110"))#.dt.date
Out[10]:
0   2011-01-01
1   2011-01-02
2   2011-01-03
3   2011-01-04
4   2011-01-05
5   2011-01-06
6   2011-01-07
7   2011-01-08
8   2011-01-09
9   2011-01-10
dtype: datetime64[ns]