ValueError: Length of passed values is 7, index implies 0

我的梦境 提交于 2019-12-23 17:40:21

问题


I am trying to get 1minute open, high, low, close, volume values from bitmex using ccxt. everything seems to be fine however im not sure how to fix this error. I know that the index is 7 because there are 7 values in the OHLCcolumns that I am getting into the dataframe. I am not sure why it is instead implying there are 0. Thanks so much this has been giving me a headache all day :(

# noinspection PyUnresolvedReferences
from datetime import datetime
# noinspection PyUnresolvedReferences
import time
# noinspection PyUnresolvedReferences
import ccxt
# noinspection PyUnresolvedReferences
import numpy as np
import pandas as pd
# noinspection PyUnresolvedReferences
from IPython.display import display, clear_output


OHLCVcolumns = ['date', 'timestamp', 'open', 'high', 'low', 'close', 'volume']

dfOHLCV = pd.DataFrame(index=[], columns=OHLCVcolumns)

bitmex = ccxt.bitmex()


def fetch_current(x):
    while True:
        if datetime.now().second == x:
            break
        time.sleep(0.5)


def fetch_mex():
    listOHLCV = bitmex.fetch_ohlcv('BTC/USD',
                                   timeframe='1m',
                                   limit=5,
                                   params={'reverse': True})

    lst = list(listOHLCV[1])

    lst.insert(0, datetime.fromtimestamp((lst[0]) / (1000 + 60 * 60 * 9 - 60)).strftime("%Y/%d/%m, %H: %M:"))

    series = pd.Series(lst, index=dfOHLCV)

    return listOHLCV, series


while True:
    fetch_current(1)

    listOHLCV, series = fetch_mex()

    dfOHLCV = dfOHLCV.append(series, ignore_index=True)


clear_output(wait=True)
display(listOHLCV)
display(dfOHLCV)

fetch_current(55)

回答1:


Not sure where you are getting the error, is it here?

series = pd.Series(lst, index=dfOHLCV)

If so you could try instead:

series = pd.Series(lst, index=OHLCVcolumns)

Since when you are running this, the index is referencing the empty dataframe dfOHLCV.



来源:https://stackoverflow.com/questions/54754887/valueerror-length-of-passed-values-is-7-index-implies-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!