Python 数据帧的二进制烛光

Python 数据帧的二进制烛光,python,list,pandas,Python,List,Pandas,蜡烛是一个列表,返回数据框列中所述的值: from binance.client import Client import pandas as pd #Binance Api data api_key = 'hidden' api_secret = 'hidden' #connect Binance client = Client(api_key, api_secret) #klines/candlesticks candles = client.get_klines(symbol=

蜡烛是一个列表,返回数据框列中所述的值:

from binance.client import Client
import pandas as pd


#Binance Api data
api_key = 'hidden'
api_secret = 'hidden'


#connect Binance
client = Client(api_key, api_secret)


#klines/candlesticks
candles = client.get_klines(symbol='BTCUSDT', interval=Client.KLINE_INTERVAL_1MINUTE)

#create dataframe for candles
candles_dataframe = pd.DataFrame(columns= ['Open time', 'Open', 'High', 'Low', 'Close', 'Volume', 'Close time', \
            'Quote asset volume', 'Number of trades', 'Taker buy base asset volume', 'Taker buy quote asset volume', \
             'Can be ignored'])

candle0 = candles[0]
candles_dataframe.append(candle0, ignore_index=True)
print(candles_dataframe)
我明白了

[1524425400000, '8918.00000000', '8918.01000000', '8911.07000000', 
'8913.94000000', '9.39563900', 1524425459999, '83771.29790726', 78, 
'6.44918600', '57506.87361929', '0']
/Volumes/Data/Dropbox/Dropbox/Coding/btc_forecast/venv/lib/python3.6/site packages/pandas/core/index/api.py:77:RuntimeWarning:“So.loc:
烛光_dataframe.loc[0]=candle0

So.loc工作:
candles\u dataframe.loc[0]=candle0

使用numpy的我的解决方案

```


我使用numpy的解决方案

```

/Volumes/Data/Dropbox/Dropbox/Coding/btc_forecast/venv/lib/python3.6/site-packages/pandas/core/indexes/api.py:77: RuntimeWarning: '<' not supported between instances of 'str' and 'int', sort order is undefined for incomparable objects`
result = result.union(other)
from binance.client import Client
import pandas as pd
import numpy as np

client = Client('', '')
def getCandles():
    df = pd.DataFrame(columns= ['Open_time', 'Open', 'High', 'Low', 'Close', 'Volume', 'Close_time'])
    candles = client.get_klines(symbol='BTCUSDT', interval=Client.KLINE_INTERVAL_1MINUTE)

    opentime, lopen, lhigh, llow, lclose, lvol, closetime = [], [], [], [], [], [], []

    for candle in candles:
        opentime.append(candle[0])
        lopen.append(candle[1])
        lhigh.append(candle[2])
        llow.append(candle[3])
        lclose.append(candle[4])
        lvol.append(candle[5])
        closetime.append(candle[6])

    df['Open_time'] = opentime
    df['Open'] = np.array(lopen).astype(np.float)
    df['High'] = np.array(lhigh).astype(np.float)
    df['Low'] = np.array(llow).astype(np.float)
    df['Close'] = np.array(lclose).astype(np.float)
    df['Volume'] = np.array(lvol).astype(np.float)
    df['Close_time'] = closetime
    return df