Created
May 22, 2017 11:39
-
-
Save Cartman0/6ddc59f1869dfe1a1eedd3696fa76327 to your computer and use it in GitHub Desktop.
内閣府の「国民の祝日」csvから日本の祝日情報取得
This file contains 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 urllib | |
def get_holidays_list( | |
holidays_jpn_url="http://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv", | |
column_name="国民の祝日月日", | |
encoding="SHIFT-JIS", | |
update_csv=False): | |
file_name = holidays_jpn_url.split("/")[-1] | |
# csv保存 | |
if update_csv: | |
urllib.request.urlretrieve(holidays_jpn_url, file_name) | |
holidays_df = pd.read_table(file_name, delimiter=",", encoding=encoding) | |
return holidays_df[column_name].tolist() | |
def get_holidays_datetime( | |
holidays_jpn_url="http://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv", | |
column_name="国民の祝日月日", | |
encoding="SHIFT-JIS", | |
update_csv=False): | |
holidays_list = get_holidays_list(holidays_jpn_url, column_name, encoding, | |
update_csv) | |
return [datetime.datetime.strptime(h, "%Y-%m-%d") for h in holidays_list] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment