Skip to content

Instantly share code, notes, and snippets.

@hwada

hwada/calendar.py

Created Aug 27, 2020
Embed
What would you like to do?
#%%
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
You can’t perform that action at this time.