Last active
July 19, 2020 05:27
-
-
Save yeiichi/25543ceb3cc9bb61f0eded426a9dab09 to your computer and use it in GitHub Desktop.
Memo on 'week of year'
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
from datetime import datetime | |
import pandas as pd | |
# Preparation of a data frame. | |
date_list = pd.date_range(datetime.now().date(), periods=14) | |
df = pd.DataFrame(date_list, columns=['DATE']) | |
day_dict = {'0':'Sun', '1':'Mon', '2':'Tue', '3':'Wed', | |
'4':'Thu', '5':'Fri', '6':'Sat'} | |
df['DAY'] = df.DATE.dt.strftime('%w') | |
df['DAY'] = list(map((lambda num: day_dict.get(num)[:1]), list(df.DAY))) | |
df['pd'] = df.DATE.dt.week | |
df['ISO'] = [i.isocalendar()[1] for i in df.DATE] | |
df['%U'] = df.DATE.dt.strftime('%U') | |
df['%W'] = df.DATE.dt.strftime('%W') | |
df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment