gpt4 book ai didi

python - 如何跟踪 Pandas 系列中的连续高点?

转载 作者:行者123 更新时间:2023-12-04 03:42:58 31 4
gpt4 key购买 nike

我想在 Pandas 的时间序列中跟踪这张图片中显示的连续高点。见下图:
enter image description here
如何用 Pandas 做到这一点?
如果你想玩一个现实生活中的例子,你可以下载股票的价格,说“MSFT”,并在你的例子中使用“关闭”。有多种方法可以下载股票价格,但这里是一种:

import yahooquery

ticker = Ticker('MSFT', asynchronous=True)

df = ticker.history()

最佳答案

返回的数据不足以执行您想要的操作。使用 SO find min/max技术将通过分析 max 起作用列,如果数据集确实有连续的局部最大值。

import yahooquery
import matplotlib.pyplot as plt
import pandas as pd, numpy as np
from scipy.signal import argrelextrema

ticker = yahooquery.Ticker('MSFT', asynchronous=True)

df = ticker.history()
df = df.reset_index()

n = 5
df['min'] = df.iloc[argrelextrema(df.close.values, np.less_equal,
order=n)[0]]['close']
df['max'] = df.iloc[argrelextrema(df.close.values, np.greater_equal,
order=n)[0]]['close']

plt.scatter(df["date"], df['min'], c='r')
plt.scatter(df["date"], df['max'], c='g')
plt.plot(df["date"], df["close"])
plt.show()

enter image description here

关于python - 如何跟踪 Pandas 系列中的连续高点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65641449/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com