Python Binance API Function Data Pull

Question:

I am trying to write a function that will pull ticker information from Binance and put into a nice chart. I am using pandas and keep getting this error: pandas.core.indexing.IndexingError: Too many indexers

Below is a portion of the code:

def getminutedata(symbol, interval, lookback):
    frame = pd.DataFrame(client.get_historical_klines(symbol,interval, lookback + 'min ago CST'))
    
    frame = frame.iloc[:,:,6]
    frame.columns = ['Time', 'Open', 'High', 'Low', 'Close', 'Volume']
    frame = frame.set_index('Time')
    frame.index = pd.to_datetime(frame.index, unit='ms')
    frame = frame.astype(float)
    
    return frame


df = getminutedata('ADAUSDT', '1m', '30')

Is there something I am missing?

Asked By: DaHawg

||

Answers:

Because pandas dataframes are 2-dimensional, you can use at most 2 indexers to index a dataframe. You’re using 3 (:, :, and 6).

Try changing this line:

frame = frame.iloc[:,:,6]

To this:

frame = frame.iloc[:,6]
Answered By: user17242583

This Is the correcte one

def getminutedata(symbol, interval, lookback):
    frame = pd.DataFrame(client.get_historical_klines(symbol,interval, lookback))
    
    frame = frame.iloc[:,:6]
    frame.columns = ['Time', 'Open', 'High', 'Low', 'Close', 'Volume']
    frame = frame.set_index('Time')
    frame.index = pd.to_datetime(frame.index, unit='ms')
    frame = frame.astype(float)
    
    return frame
Answered By: BELAID AMAR
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.