<jupyter_start><jupyter_text>https://pandas-datareader.readthedocs.io/en/latest/remote_data.htmlY|AMZN|Amazon.com, Inc. - Common Stock|Q|Q|N|100|N|N||AMZN|N<jupyter_code>date_from = datetime.date(2019, 1, 1)
date_to = datetime.date(2020, 8, 31)
df = getSingleAssetData('AMZN', date_from, date_to) # read Amazon.com, Inc
df.head()
agg_dict = {'Open': 'first',
          'High': 'max',
          'Low': 'min',
          'Close': 'last',
          'Adj Close': 'last',
          'Volume': 'mean'}
df.resample('W').agg(agg_dict).head()
df.resample('W', label='left').agg(agg_dict).head()
df.resample('W', label='left', closed='left').agg(agg_dict).head()
# official downsampling
index = pd.date_range('1/1/2000', periods=9, freq='T')
series = pd.Series(range(9), index=index)
series
series.resample('3T').sum()
series.resample('3T', label='right').sum()
series.resample('3T', label='right', closed='right').sum()<jupyter_output><empty_output><jupyter_text>(Optional) How to gain OHLCV data from close prices and volume?<jupyter_code>df_ = df.loc[:, ['Close', 'Volume']]
df_.head()
df_['Close'].resample('W').ohlc().head()
df_['Volume'].resample('W').mean().head()
last = pd.concat([df['Close'].resample('W').ohlc(), df['Volume'].resample('W').mean()], axis=1)
last.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2274479568234387, 'fraction_numerical': 0.02158828064764842, 'mean_word_length': 5.978494623655914, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '587049', 'license': 'MIT', 'n_tokens_mistral': 512, 'n_tokens_neox': 492, 'n_words': 76, 'path': 'Mastering DataFrame - how to aggregate OHLCV data in a different time period.ipynb', 'repo_name': 'yuyasugano/finance_python', 'size': '1297'}