@MA K
You stated "I don't completely understand what .last() does" Here's a little bit of an explanation...
In Pandas 0.18.0 the approach to resampling changed (see http://pandas.pydata.org/pandas-docs/version/0.18.0/whatsnew.html). Resample doesn't actually return a value or a series of values, it returns a 'resampler' object. Similar to the groupby method. To get actual values one needs to ask that resampler object for data. It's a two step process. First make the resampler object, then ask that object to perform operations. If you want the last value of each 'bucket' of the resampler simply append the 'last()' method...
# Get some 1 minute data
prices_1m = get_pricing('AAPL', start_date="2017-03-01", end_date="2017-03-01", fields='price', frequency='minute')
# Get the last value of each resampled bucket
resample_5m = prices_1m.resample('5T', closed='right', label='right').last()
You can also ask the resampler object to do other things than simply getting the last value of each bucket. You can get the sum, the mean, the min, the max, and a whole lot of other things. You can even create your own function to apply to each bucket.
Hope that makes sense. Always specify a method like 'last()', 'mean()' or something. If you don't, then you aren't exactly sure what the resampler object is giving you (though it does seem it defaults to last() )
If you are curious, you can get a list of all the current methods for a resampler. An easy way to get a list of all the available methods is to use the 'help' function in a notebook. Once you have an object instantiated (so assume you already ran the code above) simply type
help(resample_5m)
Here's an augmented list of all the available methods...
```
aggregate(self, arg, args, **kwargs)
| Apply aggregation function or functions to resampled groups, yielding
| most likely Series but in some cases DataFrame depending on the output
| of the aggregation function
|
| apply = aggregate(self, arg, *args, **kwargs)
| Apply aggregation function or functions to resampled groups, yielding
| most likely Series but in some cases DataFrame depending on the output
| of the aggregation function
|
| asfreq(self)
| return the values at the new freq,
| essentially a reindex with (no filling)
|
| backfill(self, limit=None)
| Backward fill the values
|
| bfill = backfill(self, limit=None)
| Backward fill the values
|
| count = f(self, _method='count')
| Compute count of group, excluding missing values
| ffill = pad(self, limit=None)
| Forward fill the values
|
| fillna(self, method, limit=None)
| Fill missing values
|
| first = f(self, _method='first')
| Compute first of group values
|
| interpolate(self, method='linear', axis=0, limit=None, inplace=False, limit_direction='forward', downcast=None, **kwargs)
| Interpolate values according to different methods.
|
| max = f(self, _method='max')
| Compute max of group values
|
| mean = f(self, _method='mean')
| Compute mean of groups, excluding missing values
|
| median = f(self, _method='median')
| Compute median of groups, excluding missing values
|
| min = f(self, _method='min')
| Compute min of group values
|
| nunique = f(self, _method='nunique')
| Returns number of unique elements in the group
|
| ohlc = f(self, _method='ohlc')
| Compute sum of values, excluding missing values
| For multiple groupings, the result index will be a MultiIndex
|
| pad(self, limit=None)
| Forward fill the values
|
| prod = f(self, _method='prod')
| Compute prod of group values
|
| sem = f(self, _method='sem')
| Compute standard error of the mean of groups, excluding missing values
|
| size = f(self, _method='size')
| Compute group sizes
|
| std(self, ddof=1)
| Compute standard deviation of groups, excluding missing values
|
| sum = f(self, _method='sum')
| Compute sum of group values
| transform(self, arg, *args, *kwargs)
| Call function producing a like-indexed Series on each group and return
| a Series with the transformed values