<jupyter_start><jupyter_text>From a DataFrame with a datetime column filter the first or last rows in an interval<jupyter_code>rng = pd.date_range('2018-01-01', periods=720, freq='30min')
rng[:5]<jupyter_output><empty_output><jupyter_text>column a has a constant integer value<jupyter_code>df = pd.DataFrame(3, index=rng, columns=['a'])
df.head()<jupyter_output><empty_output><jupyter_text>only use the firts record of chunks of 3 hourswith numerics you can use mean(), max(), min() etc<jupyter_code>df.resample('3H').mean().head()
df = pd.DataFrame(np.random.choice(['A', 'B'], len(rng)), index=rng, columns=['a'])
df.head()<jupyter_output><empty_output><jupyter_text>with strings use pad(), this does not do anything with the string value<jupyter_code>df.resample('2H').pad().head()<jupyter_output><empty_output><jupyter_text>mulitple columns still okay<jupyter_code>df = pd.DataFrame(np.random.choice(['A', 'B', 'C'], size=(len(rng), 2)), index=rng, columns=['a', 'b']) 
df.head()
df.resample('2H').pad().head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1781609195402299, 'fraction_numerical': 0.019157088122605363, 'mean_word_length': 8.858490566037736, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '364360', 'license': 'MIT', 'n_tokens_mistral': 402, 'n_tokens_neox': 390, 'n_words': 79, 'path': 'pandas/Time series.ipynb', 'repo_name': 'hbeemster/python-snippets', 'size': '1044'}