I'm using pandas.DataFrame.resample on the data set below:
And I applied my own function, which is defined as:
def btc_resample(df):
if len(df) > 0:
print(type(df))
print(df)
print(df['close'])
print(df['high'])
print(df['low'])
ret = df.head(1).copy()
ret['close'] = df['close'].values[-1]
ret['high'] = df['high'].max()
ret['low'] = df['low'].min()
print(ret)
return ret
else:
return None
So the implementation of the resample is:
data.resample('5min').apply(btc_resample)
As you can see, I printed out all the looped DataFrames in the resample process, but the first two prints are actually Series, one of which even has a name of a timestamp. I don't know why are there 2 Series in the resample loop. console snapshot
What's more, why don't the lines print(df['close']), print(df['high']), print(df['low']) raise any error? The 2 Series shouldn't contain any of these columns.