python - 修订 - 如何从 pandas 中检索数据
问题描述
我正在尝试从以下结果中检索最新数据。
我正在运行的代码是:
import datetime
from Historic_Crypto import HistoricalData
# Time Setup
now_bsc = datetime.datetime.now()
now = (now_bsc.strftime("%Y-%m-%d-%H-%M"))
start_bsc = (datetime.datetime.now() - datetime.timedelta(minutes=10))
start = (start_bsc.strftime("%Y-%m-%d-%H-%M"))
"""print(start)
print(now)"""
# Pull OHLC Crypto
new = HistoricalData('BTC-USD', 60, start, now).retrieve_data()
print(new)
这是结果
Checking input parameters are in the correct format...
Formatting Dates...
Checking if ticker supplied is available on the CoinBase Pro API...
Connected to the CoinBase Pro API...
Ticker 'BTC-USD' found at the CoinBase Pro API, continuing to extraction...
Data Extracted from API...
low high open close volume
time
2021-05-12 21:18:00 54577.75 54641.08 54637.08 54582.91 14.041055
2021-05-12 21:19:00 54572.71 54610.19 54582.91 54599.86 3.327732
2021-05-12 21:20:00 54599.86 54691.49 54599.86 54678.31 17.552511
2021-05-12 21:21:00 54677.93 54725.75 54677.93 54711.22 5.963198
2021-05-12 21:22:00 54703.62 54756.39 54710.24 54753.88 11.564766
2021-05-12 21:23:00 54750.42 54800.47 54753.88 54768.64 13.601058
2021-05-12 21:24:00 54707.11 54768.64 54768.64 54738.99 11.131357
2021-05-12 21:25:00 54499.99 54739.49 54738.89 54669.53 37.366287
2021-05-12 21:26:00 54665.96 54748.10 54665.97 54743.89 7.932319
2021-05-12 21:27:00 54719.23 54752.19 54736.09 54734.70 9.654189
2021-05-12 21:28:00 54719.97 54749.00 54725.91 54748.99 6.386556
Process finished with exit code 0
如何检索 2021-05-12 21:28:000 的数据“低”和“高”?
解决方案
此 API 返回 pandas Dataframe 对象。
您可以在此处使用 pandas 数据帧过滤器选项。
例如:
data = new.loc[(new['time'] == '2021-05-12 21:28:000')]
low = data['low']
high = data['high']
推荐阅读
- vba - Word 另存为默认值和迭代
- c# - Autofac试图加载不相关的类
- python - 在数据流中找到迄今为止的前 K 个最小值
- wpf - 如何让整个团队在 Visual Studio 中拥有完全相同的设置,以便每个开发人员都有相同的先决条件和设置来工作?
- javascript - 更新消息角色 discord.js
- python - 如何测试在某些情况下必须无限循环的函数?
- firebase - Firebase 帐户验证电子邮件无法在 Android 上使用动态链接 URL 发送
- c++ - 为什么将类对象作为参数的外部函数在返回相同的对象时会调用移动构造函数
- javascript - 获取可能的问题答案路径 (JavaScript)
- tensorflow - 如何在不干扰 TF>2.0 Model Graph 的情况下实现带有张量评估的自定义 Keras 序数损失函数?