ValueError: Length of passed values is 7, index implies 0
ValueError: Length of passed values is 7, index implies 0
我正在尝试使用 ccxt 从 bitmex 获取 1 分钟的开盘价、最高价、最低价、收盘价和交易量值。一切似乎都很好,但我不确定如何解决此错误。我知道索引是 7,因为我进入数据框的 OHLC 列中有 7 个值。我不确定为什么它暗示有 0。非常感谢,这让我一整天都很头疼:(
# 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)
不确定错误在哪里,是这里吗?
series = pd.Series(lst, index=dfOHLCV)
如果是这样,您可以试试:
series = pd.Series(lst, index=OHLCVcolumns)
因为当你是 运行 这个时,索引引用空数据帧 dfOHLCV。
我正在尝试使用 ccxt 从 bitmex 获取 1 分钟的开盘价、最高价、最低价、收盘价和交易量值。一切似乎都很好,但我不确定如何解决此错误。我知道索引是 7,因为我进入数据框的 OHLC 列中有 7 个值。我不确定为什么它暗示有 0。非常感谢,这让我一整天都很头疼:(
# 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)
不确定错误在哪里,是这里吗?
series = pd.Series(lst, index=dfOHLCV)
如果是这样,您可以试试:
series = pd.Series(lst, index=OHLCVcolumns)
因为当你是 运行 这个时,索引引用空数据帧 dfOHLCV。