.resample('5Min').head() Attribute error

Hello, I've been trying out the resampling method exposed in your video and e-book and what I've got from running the code is





Input:



import pandas as pd

import numpy as np



duration = pd.date_range('1/1/2012', periods=1000, freq='S')

ts = pd.Series(np.random.randint(0,5000, len(duration)), index=duration)

ts.resample('5Min').sum()



Output:

 

2012-01-01 00:00:00    687020
2012-01-01 00:05:00    747341
2012-01-01 00:10:00    706345
2012-01-01 00:15:00    249775
Freq: 5T, dtype: int32

Input:



ts.head()



Output:

 

2012-01-01 00:00:00    2569
2012-01-01 00:00:01    3238
2012-01-01 00:00:02    2631
2012-01-01 00:00:03    4249
2012-01-01 00:00:04     969
Freq: S, dtype: int32

""But:

Input;



ts.resample('5Min').head()



Output:

 

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-0ba080de54bb> in <module>
----> 1 ts.resample('5Min').head()

C:\Anaconda3\lib\site-packages\pandas\core\resample.py in __getattr__(self, attr)
    108             return self[attr]
    109 
--> 110         return object.__getattribute__(self, attr)
    111 
    112     def __iter__(self):

AttributeError: 'DatetimeIndexResampler' object has no attribute 'head'

It looks like .head() is not an object attributable to resample('5Min)



Could you please help me run this code and reply with possible causes and solutions?



Thank you



"possible causes" - once you resample you need to apply some sort of aggregration ( like sum , mean)  on the sampled timeseries. That is why the option to print the head of a resampled timeseries isn't available. It doesn't mean anthing i.e taking data with frequency of seconds and then simply bundling them together in frequncy of 5 mins will mean something only if we apply some operation like mean ,sum etc on it. 



"solutions" - can you elaborate more on what you're trying to do here ? So that we can think of some code suggestions for the same. 



You can have a look at this link for the possible aggregrations to apply based on the attribute you might be using ( look at the "
Get data at a custom frequency" heading ) :  https://blog.quantinsti.com/stock-market-data-analysis-python/#intraday