Created
August 27, 2020 04:01
-
-
Save hwada/3606a96df7967d7e556be6be5bc08d0c to your computer and use it in GitHub Desktop.
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 | |
df = pd.read_csv('https://www.city.yokohama.lg.jp/city-info/koho-kocho/koho/topics/corona-data.files/141003_yokohama_covid19_patients.csv', encoding='UTF-8') | |
#%% | |
import datetime | |
weeks = [0] * 8 | |
output = [] | |
dates = pd.to_datetime(df['公表日']) | |
start = dates[0] | |
stop = dates.iloc[-1] | |
# 月曜スタートにしたい | |
start -= datetime.timedelta(days=start.weekday()) | |
weeks[0] = start | |
for n in range((stop - start).days + 1): | |
date = start + datetime.timedelta(days = n) | |
weekday = date.weekday() | |
if weekday == 0: | |
output.append(weeks) | |
weeks = [0] * 8 | |
weeks[0] = date | |
count = (dates == date).sum() | |
weeks[weekday + 1] = count | |
if stop.weekday() != 6: | |
output.append(weeks) | |
#%% | |
weekstr = ['', '月', '火', '水', '木', '金', '土', '日'] | |
o2 = pd.DataFrame(output, columns = weekstr) | |
o2.to_csv('calendar.csv', encoding='Shift_JIS') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment