亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復這個“關鍵錯誤:t”我在編寫一段時間循環時得到的?

如何修復這個“關鍵錯誤:t”我在編寫一段時間循環時得到的?

慕容森 2022-09-13 19:50:47
我寫了這段代碼,然后我在下面寫了一個錯誤。有一個 while 循環,它允許我獲取受 1000 列限制的數據,該時間與我在reapeat_rounds變量中描述的時間一樣長,但是當我試圖使用該循環時,會引發“keyerror:t”。如果我做reapeat_rounds = 0,我不會得到這樣的錯誤,但如果我這樣做,這意味著雖然循環不起作用,如果循環工作,我得到錯誤請幫助我解決該錯誤,謝謝。class Binance:    def __init__(self):        self.base = 'https://api.binance.com'        self.endpoints = {            "order": '/api/v3/order',            "testOrder": '/api/v3/order/test',            "allOrders": '/api/v3/allOrders',            "klines": '/api/v3/klines',            "exchangeInfo": '/api/v3/exchangeInfo'        }        self.headers = {"X-MBX-APIKEY": binance_keys['api_key']}    def GetLongerSymbolData(self, symbol:str, interval:str, limit:int=1000, end_time=False):        # Basicall, we will be calling the GetSymbolData as many times as we need         # in order to get all the historical data required (based on the limit parameter)        # and we'll be merging the results into one long dataframe.        repeat_rounds = 1        if limit > 1000:            repeat_rounds = int(limit/1000)        initial_limit = limit % 1000        if initial_limit == 0:            initial_limit = 1000        # First, we get the last initial_limit candles, starting at end_time and going        # backwards (or starting in the present moment, if end_time is False)        df = self.GetSymbolData(symbol, interval, limit=initial_limit, end_time=end_time)        while repeat_rounds > 0:            # Then, for every other 1000 candles, we get them, but starting at the beginning            # of the previously received candles.            df2 = self.GetSymbolData(symbol, interval, limit=1000, end_time=df['time'[0]])            df = df2.append(df, ignore_index = True)            repeat_rounds = repeat_rounds - 1        return dfData = Binance()m = Data.GetLongerSymbolData('BTCUSDT','1h')
查看完整描述

1 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

難道你不想更換線路嗎

df2 = self.GetSymbolData(symbol, interval, limit=1000, end_time=df['time'[0]])

使用類似的東西

df2 = self.GetSymbolData(symbol, interval, limit=1000, end_time=df['time'][0])

?

在這里,將 應用于字符串,這基本上只是導致字符串作為數據幀的鍵。[0]'time''t'


查看完整回答
反對 回復 2022-09-13
  • 1 回答
  • 0 關注
  • 83 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號