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

2024/9/28 1:27:40

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_outputOHLCVcolumns = ['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:breaktime.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, serieswhile 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)
Answer

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://en.xdnf.cn/q/71391.html

Related Q&A

What is pythons strategy to manage allocation/freeing of large variables?

As a follow-up to this question, it appears that there are different allocation/deallocation strategies for little and big variables in (C)Python. More precisely, there seems to be a boundary in the ob…

Why is cross_val_predict so much slower than fit for KNeighborsClassifier?

Running locally on a Jupyter notebook and using the MNIST dataset (28k entries, 28x28 pixels per image, the following takes 27 seconds. from sklearn.neighbors import KNeighborsClassifierknn_clf = KNeig…

Do I need to do any text cleaning for Spacy NER?

I am new to NER and Spacy. Trying to figure out what, if any, text cleaning needs to be done. Seems like some examples Ive found trim the leading and trailing whitespace and then muck with the start/st…

Hi , I have error related to object detection project

I have error related to simple object detection .output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()] IndexError: invalid index to scalar variable.import cv2.cv2 as cv import…

What is the fastest way to calculate / create powers of ten?

If as the input you provide the (integer) power, what is the fastest way to create the corresponding power of ten? Here are four alternatives I could come up with, and the fastest way seems to be usin…

How to disable date interpolation in matplotlib?

Despite trying some solutions available on SO and at Matplotlibs documentation, Im still unable to disable Matplotlibs creation of weekend dates on the x-axis.As you can see see below, it adds dates to…

Continuous error band with Plotly Express in Python [duplicate]

This question already has answers here:Plotly: How to make a figure with multiple lines and shaded area for standard deviations?(5 answers)Closed 2 years ago.I need to plot data with continuous error …

How to preprocess training set for VGG16 fine tuning in Keras?

I have fine tuned the Keras VGG16 model, but Im unsure about the preprocessing during the training phase.I create a train generator as follow:train_datagen = ImageDataGenerator(rescale=1./255) train_ge…

Using Python like PHP in Apache/Windows

I understand that I should use mod_wsgi to run Python, and I have been trying to get that set up, but Im confused about it:This is a sample configuration I found for web.py:LoadModule wsgi_module modul…

django-oauth-toolkit : Customize authenticate response

I am new to Django OAuth Toolkit. I want to customize the authenticate response.My authenticate url configuration on django application is : url(authenticate/,include(oauth2_provider.urls, namespace=oa…