<jupyter_start><jupyter_text>Group by week and average<jupyter_code>from src.utils import num2date, date2num, week_num, get_weeks
df = market[market.IsinIdx == 24643].copy()
weeks = get_weeks(20150105)
df['week'] = df.DateKey.apply(lambda x: week_num(weeks, x))
weekly_values = df.groupby('week')[['Price', 'Yield', 'ZSpread']].agg('mean')
week_num(weeks, 20180423)
df[df.week<=172].tail(10)
weekly_values[weekly_values<172].tail(10)
def get_previous_weeks(current_week, previous_weeks):
    weeks_idxs = [current_week - w_off for w_off in previous_weeks]
    return weekly_values.loc[current_week] - weekly_values.loc[weeks_idxs] 
get_previous_weeks(171, [1,2,4,8,16])
get_previous_weeks(171, [1,2,4,8,16])
df.Price.plot(figsize=(15,5))
weekly_values.Price.plot(figsize=(15,5))
weeks[:10]
date2num(weeks[0])
num2date(20150105) + timedelta(7)
num2date(20160609)
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15883668903803133, 'fraction_numerical': 0.0894854586129754, 'mean_word_length': 8.944444444444445, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '536286', 'license': 'MIT', 'n_tokens_mistral': 415, 'n_tokens_neox': 360, 'n_words': 54, 'path': 'notebooks/robert/RA-11-Bond-EDA.ipynb', 'repo_name': 'Robert-Alonso/DSG-2018', 'size': '894'}