Have a time series(ts) indexed by DatatimeIndex, want to group it by 10 minutes
index x y z
ts1 ....
ts2 ....
...
I know how to group by 1 minute
def group_by_minute(timestamp):
year = timestamp.year
month = timestamp.month
day = timestamp.day
hour = timestamp.hour
minute = timestamp.minute
return datetime.datetime(year, month, day, hour, minute)
then
ts.groupby(group_by_minute, axis=0)
my customized function (roughly)
def my_function(group):
first_latitude = group['latitude'].sort_index().head(1).values[0]
last_longitude = group['longitude'].sort_index().tail(1).values[0]
return first_latitude - last_longitude
so the ts DataFrame should definitely contains 'latitude' and 'longitude' columns
When using TimeGrouper
ts.groupby(pd.TimeGrouper(freq='100min')).apply(my_function)
I got the following errors,
TypeError: cannot concatenate a non-NDFrame object
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…