Last active
August 11, 2017 00:11
-
-
Save ksomemo/34c0e447d12376b87d1602a1558af390 to your computer and use it in GitHub Desktop.
月の予定表のテンプレ(祝日情報付き)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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["note"] = "" | |
print(tabulate.tabulate(df, headers="keys", tablefmt="pipe", missingval="", showindex=False)) | |
make_schedule_table("2017年1月1日") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment