我想切片这个对象的前三个结果,我尝试将它转换为几个类,但找不到解决方案。我可以打印整个原始对象,但我不能对其进行切片。
import datetime
import krakenex
from pykrakenapi import KrakenAPI
import pandas as pd
import numpy as np
api = krakenex.API()
k = KrakenAPI(api)
Now = datetime.datetime.utcnow()#date and time now
DifferenceTime = datetime.timedelta(minutes=15) # establish time difference
PreviousTime = Now - DifferenceTime
ohlc= k.get_ohlc_data("XBTEUR",interval=5,since=15)
lista=np.array(ohlc,dtype=object)#ragged nested deprecation turn around with dtype=object
listapanda=pd.DataFrame(lista)
print(type(ohlc))
print(type(lista))
print(type(listapanda))
print(ohlc[0:3])
print(lista[0:3])
print("----------------")
print(listapanda.loc[0])
print("----------------")
print(listapanda.loc[1])
print("----------------")
print(listapanda.loc[2])
print("----------------")
print(listapanda.loc[3])
结果我得到了这个
<class 'tuple'>
<class 'numpy.ndarray'>
<class 'pandas.core.frame.DataFrame'>
( time open high ... vwap volume count
dtime ...
2021-05-04 08:20:00 1620116400 46425.5 46465.0 ... 46431.4 5.318430 216
2021-05-04 08:15:00 1620116100 46310.9 46470.2 ... 46403.3 7.706564 275
2021-05-04 08:10:00 1620115800 46600.0 46600.1 ... 46410.0 35.635535 519
2021-05-04 08:05:00 1620115500 46608.1 46651.7 ... 46625.7 11.487916 349
2021-05-04 08:00:00 1620115200 46594.5 46626.3 ... 46584.9 19.179633 317
... ... ... ... ... ... ... ...
2021-05-01 20:45:00 1619901900 48087.6 48087.6 ... 48060.2 2.187421 117
2021-05-01 20:40:00 1619901600 48085.1 48089.5 ... 48085.2 4.806902 74
2021-05-01 20:35:00 1619901300 48071.7 48085.0 ... 48067.1 3.734310 100
2021-05-01 20:30:00 1619901000 48049.7 48077.4 ... 48071.4 2.844302 88
2021-05-01 20:25:00 1619900700 47950.1 48049.8 ... 47966.4 7.933266 262
[720 rows x 8 columns], 1620116100)
[ time open high ... vwap volume count
dtime ...
2021-05-04 08:20:00 1620116400 46425.5 46465.0 ... 46431.4 5.318430 216
2021-05-04 08:15:00 1620116100 46310.9 46470.2 ... 46403.3 7.706564 275
2021-05-04 08:10:00 1620115800 46600.0 46600.1 ... 46410.0 35.635535 519
2021-05-04 08:05:00 1620115500 46608.1 46651.7 ... 46625.7 11.487916 349
2021-05-04 08:00:00 1620115200 46594.5 46626.3 ... 46584.9 19.179633 317
... ... ... ... ... ... ... ...
2021-05-01 20:45:00 1619901900 48087.6 48087.6 ... 48060.2 2.187421 117
2021-05-01 20:40:00 1619901600 48085.1 48089.5 ... 48085.2 4.806902 74
2021-05-01 20:35:00 1619901300 48071.7 48085.0 ... 48067.1 3.734310 100
2021-05-01 20:30:00 1619901000 48049.7 48077.4 ... 48071.4 2.844302 88
2021-05-01 20:25:00 1619900700 47950.1 48049.8 ... 47966.4 7.933266 262
[720 rows x 8 columns]
1620116100]
----------------
0 time open h...
Name: 0, dtype: object
----------------
0 1620116100
Name: 1, dtype: object
----------------
Traceback (most recent call last):
return self._range.index(new_key)
ValueError: 2 is not in range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
raise KeyError(key) from err
KeyError: 2
Process finished with exit code 1
我已经连续搜索了两天,找不到解决方案。在 numpy ndarray 文档上。
我是 python 的新手,尽我所能,我认为这是某种特殊问题。