【发布时间】:2020-05-09 19:56:34
【问题描述】:
我有一个包含三列的 .txt 文件:时间、代码、价格。时间间隔为 15 秒。看起来像这样上传到 jupyter notebook 并放入 Pandas DF 中。
time ticker price
0 09:30:35 EV 33.860
1 00:00:00 AMG 60.430
2 09:30:35 AMG 60.750
3 00:00:00 BLK 455.350
4 09:30:35 BLK 451.514
... ... ... ...
502596 13:00:55 TLT 166.450
502597 13:00:55 VXX 47.150
502598 13:00:55 TSLA 529.800
502599 13:00:55 BIDU 103.500
502600 13:00:55 ON 12.700
# NOTE: the first set of data has the data at market open for -
# every other time point, so that's what the 00:00:00 is.
#It is only limited to the 09:30:35 data.
我需要创建一个接受输入的函数(一个代码),然后创建一个条形图,以 5 分钟的刻度显示数据(数据是每 20 秒,因此每 15 个时间点)。
到目前为止,我一直在考虑将 hh:mm:ss 的“mm”部分分开,以便在另一列中获取分钟,然后正确地执行一个看起来像这样的 for 循环:
for num in df['mm']:
if num %5 == 0:
print('tick')
然后以某种方式将“tick”附加到“时间”列中每 5 分钟的数据(我不确定我会如何做到这一点),然后使用时间列作为索引并且只使用带有“勾选”索引(某种 if 语句)。我不确定这是否有意义,但我对此表示空白。
【问题讨论】:
标签: python pandas matplotlib