熊猫重新采样无法正常工作

时间:2018-11-01 22:43:20

标签: python pandas dataframe

Here's data.pkl和下面的代码。我正在获取SMA20的价值,但对于SMA200,我正在获取NaN。数据集足够大,可以找到SMA200的平均值。我在搞什么鬼?

df = pd.read_pickle("data.pkl")
if not df.empty:    
    df = df.astype(dtype={"volume": "int32", "close": "float32",
                                 "date": 'datetime64[ns]'})        
    df.date = df.date - pd.Timedelta('-5 hours 30 min')    
    df.set_index('date', inplace=True, drop=True)            
    df = df.resample('5Min').agg({'close': 'ohlc', 'volume': 'sum'})   
    df3 = pd.merge(df['close'], df['volume'], on="date")        
    df3['SMA20'] = df3['close'].rolling(window=20).mean()
    df3['SMA200'] = df3['close'].rolling(window=200).mean()

0 个答案:

没有答案