如何使用来自雅虎财经的数据创建烛台图?

发布于 2025-01-10 11:42:37 字数 2081 浏览 1 评论 0原文

我使用 yfinanceplotly 库 (python 2.7) 获取欧元/美元数据,然后创建烛台图< /强>。

这是我从雅虎财经下载数据的代码:

import yfinance as yf

data = yf.download(tickers='EURUSD=X', period='1d', interval='30m')

示例输出:

data.tail(10)


                               Open         High    Low Close   Adj Close     Volume
                 Datetime                       
2022-02-25 17:30:00+00:00   1.125239    1.125239    1.124101    1.124354    1.124354    0
2022-02-25 18:00:00+00:00   1.124480    1.125873    1.124480    1.125492    1.125492    0
2022-02-25 18:30:00+00:00   1.125619    1.126507    1.125619    1.126126    1.126126    0
2022-02-25 19:00:00+00:00   1.125999    1.126507    1.125492    1.126253    1.126253    0
2022-02-25 19:30:00+00:00   1.126634    1.126888    1.125366    1.126634    1.126634    0
2022-02-25 20:00:00+00:00   1.126888    1.127015    1.126126    1.126634    1.126634    0
2022-02-25 20:30:00+00:00   1.126507    1.127650    1.126507    1.127015    1.127015    0
2022-02-25 21:00:00+00:00   1.127142    1.127523    1.126761    1.127523    1.127523    0
2022-02-25 21:30:00+00:00   1.127650    1.127777    1.127396    1.127777    1.127777    0
2022-02-25 22:00:00+00:00   1.127142    1.127142    1.127142    1.127142    1.127142    0

我的目标是绘制 candlestick 样式图表,我尝试使用此代码来创建图表:

date_time = data.select_dtypes(['datetime64'])
fig = go.Figure(data=[go.Candlestick(x=date_time,
                                     open=data['Open'],
                                     high=data['High'],
                                     low=data['Low'],
                                     close=data['Close'])])

fig.show()

弹出窗口什么也不显示(空白窗口):

“结果图"

我做错了什么?我该怎么做?

I'm using yfinance and plotly libraries (python 2.7) to get Euro/USD data, and then create a candlestick chart.

This is my code to download data from yahoo finance:

import yfinance as yf

data = yf.download(tickers='EURUSD=X', period='1d', interval='30m')

sample output:

data.tail(10)


                               Open         High    Low Close   Adj Close     Volume
                 Datetime                       
2022-02-25 17:30:00+00:00   1.125239    1.125239    1.124101    1.124354    1.124354    0
2022-02-25 18:00:00+00:00   1.124480    1.125873    1.124480    1.125492    1.125492    0
2022-02-25 18:30:00+00:00   1.125619    1.126507    1.125619    1.126126    1.126126    0
2022-02-25 19:00:00+00:00   1.125999    1.126507    1.125492    1.126253    1.126253    0
2022-02-25 19:30:00+00:00   1.126634    1.126888    1.125366    1.126634    1.126634    0
2022-02-25 20:00:00+00:00   1.126888    1.127015    1.126126    1.126634    1.126634    0
2022-02-25 20:30:00+00:00   1.126507    1.127650    1.126507    1.127015    1.127015    0
2022-02-25 21:00:00+00:00   1.127142    1.127523    1.126761    1.127523    1.127523    0
2022-02-25 21:30:00+00:00   1.127650    1.127777    1.127396    1.127777    1.127777    0
2022-02-25 22:00:00+00:00   1.127142    1.127142    1.127142    1.127142    1.127142    0

My goal is to plot a candlestick style chart, I tried this code in order to create a chart:

date_time = data.select_dtypes(['datetime64'])
fig = go.Figure(data=[go.Candlestick(x=date_time,
                                     open=data['Open'],
                                     high=data['High'],
                                     low=data['Low'],
                                     close=data['Close'])])

fig.show()

The popup window showing nothing(a blank window):

Resulting figure

What am I doing wrong? and how can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坦然微笑 2025-01-17 11:42:37

根据@r-beginners 评论。 data.index.select_dtypes(['datetime64']) 没有日期时间类型的列。您想要使用 xaxis 的索引值,因此不需要整行,只需使用 xaxis 的索引即可。

import yfinance as yf
import plotly.graph_objects as go

data = yf.download(tickers='EURUSD=X', period='1d', interval='30m')

fig = go.Figure(data=[go.Candlestick(x=data.index,
                                     open=data['Open'],
                                     high=data['High'],
                                     low=data['Low'],
                                     close=data['Close'])])

fig.show()

as per @r-beginners comment. data.index.select_dtypes(['datetime64']) there are no columns of type date time. You want to use the index values for xaxis, hence whole line is not needed and just use index for xaxis.

import yfinance as yf
import plotly.graph_objects as go

data = yf.download(tickers='EURUSD=X', period='1d', interval='30m')

fig = go.Figure(data=[go.Candlestick(x=data.index,
                                     open=data['Open'],
                                     high=data['High'],
                                     low=data['Low'],
                                     close=data['Close'])])

fig.show()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文