-1

I'm using pandas.DataFrame.resample on the data set below:

data snapshot

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.

1 Answers1

0

You are getting 2 series because in you are printing ret which means that when you execute function it will print(ret) hence first series and then when you execute next line return(ret) it will return ret hence, second series.

Hope I explained you what you wanted to ask. Thank you