熊猫OHLC仅随时间绘制高值

问题描述 投票:0回答:1

我有一个包含以下实时数据的文本文件。

1,16:20:35
2,16:20:40
3,16:21:41
4,16:21:50
5,16:21:52
6,16:22:20
7,16:22:42
8,16:23:44

我只想绘制相对于时间的高值。以下是我尝试过的。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data = pd.read_csv(('output.txt'), header=0, sep=',', names=['count', 'time'])

data['time'] = pd.to_datetime(data['time'], format='%H:%M:%S')

data = data.set_index(['time'])
df2 = data.resample('1T').ohlc().ffill()
print(df2)
fig, ax = plt.subplots()
df2.plot(time="time", high="high value", ax=ax)
plt.draw()

plt.show()
python-3.x pandas resampling ohlc
1个回答
0
投票
fig, ax = plt.subplots() df2[('count', 'high')].plot(ax=ax)

我还建议从df2中删除MultiIndex,因为只需要一个级别。即:

df2.columns = df2.columns.droplevel(0)
fig, ax = plt.subplots()
df2['high'].plot(ax=ax)
© www.soinside.com 2019 - 2024. All rights reserved.