如何使用来自雅虎财经的数据创建烛台图?
我使用 yfinance
和 plotly
库 (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):
What am I doing wrong? and how can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据@r-beginners 评论。
data.index.select_dtypes(['datetime64'])
没有日期时间类型的列。您想要使用 xaxis 的索引值,因此不需要整行,只需使用 xaxis 的索引即可。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.