如何在python3的数据框中修复``无法将类型''时间戳''与类型''int''进行比较?

时间:2019-07-16 04:16:50

标签: python-3.x dataframe series

我想将2个数字列表相乘。 一个是数据框,另一个是序列。 但是不能。并有错误 “无法将类型“时间戳”与类型“ int”进行比较,无法定义对象的排序顺序”

def mf(src):
    diff = src['hlc3'].diff()
    upwards = pd.Series([0 if cur <= 0 else cur for cur in diff])
    volume_upwards = src['volume'] * upwards
    print(diff.index)       # DatetimeIndex(['2013-12-27', '2013-12-28' ...
    print(upwards.index)    # RangeIndex(start=0, stop=5, step=1)
    print(src['volume')
    print(upwards)
    print(volume_upwards)
    return volume_upwards

candles = pybithumb.get_ohlcv('BTC')
candles = candles[0:3]
candles['hlc3'] = (candles['high'] + candles['close'] + candles['low']) / 3
x = mf(candles)


--- when I run this code it shows me like this

DatetimeIndex(['2013-12-27', '2013-12-28', '2013-12-29'], dtype='datetime64[ns]', freq=None)
RangeIndex(start=0, stop=3, step=1)

--- src['volume'] ---
2013-12-27     3.780
2013-12-28    12.000
2013-12-29    19.058
Name: volume, dtype: float64

--- upwards ---
0       NaN
1    1000.0
2       0.0
dtype: float64

--- src['volume'] * upwards ---
2013-12-27 00:00:00   NaN
2013-12-28 00:00:00   NaN
2013-12-29 00:00:00   NaN
0                     NaN
1                     NaN
2                     NaN
dtype: float64

我希望src'volume'*之外的向上(dtype:float64)为volume_upwards。 我认为问题是两个指数。 一个是DatetimeIndex,另一个是RangeIndex。我怎么乘两个?

0 个答案:

没有答案