[英]How can I make sure that dates display as in Yahoo Finance / Google Finance without accounting for weekends?
I'm currently using Alpha-Vantage to fetch financial data with 1 min intervals.我目前正在使用 Alpha-Vantage 以 1 分钟的间隔获取财务数据。
amd=ts.get_intraday(symbol=symbol, outputsize='full', interval=interval)
amd=pd.DataFrame(amd[0])
amd.drop(amd.index[-1])
and I'm getting the following output我得到以下输出
...
2020-03-02 09:37:00 46.1000 46.1265 45.7427 45.7427 701690.0
2020-03-02 09:36:00 46.0700 46.0700 45.9300 46.0500 725661.0
2020-03-02 09:35:00 46.1100 46.1100 46.1100 46.1100 484583.0
2020-03-02 09:34:00 46.7500 46.8000 46.3000 46.3447 614596.0
2020-03-02 09:33:00 46.9642 47.2300 46.6800 46.7400 528517.0
2020-03-02 09:32:00 47.6100 47.6100 46.7000 46.9800 770555.0
2020-03-02 09:31:00 47.4000 47.6800 47.1000 47.5500 3504998.0
2020-02-28 16:00:00 45.1500 45.5300 45.1400 45.4700 895713.0
2020-02-28 15:59:00 45.0900 45.1600 45.0100 45.1500 411553.0
2020-02-28 15:58:00 44.8750 45.0900 44.8400 45.0800 434739.0
2020-02-28 15:57:00 44.8400 44.9100 44.8100 44.8560 327619.0
2020-02-28 15:56:00 44.7500 44.9100 44.6800 44.8450 363272.0
2020-02-28 15:55:00 44.4800 44.7700 44.4604 44.7400 305512.0
...
As you can see, the date jumps from Feb. 28th to March 2nd, as it should.如您所见,日期从 2 月 28 日跳到了 3 月 2 日,这是理所当然的。 However, when plotting it in matplotlib...
但是,在 matplotlib 中绘制时...
amd['4. close'].plot()
plt.title('AMD')
plt.show()
...I'm getting the following graph, where mathplotlib compensates for the lack of data in weekends and at closed market by drawing a straight line from one datapoint to the other. ...我得到了下图,其中mathplotlib通过从一个数据点到另一个数据点绘制一条直线来补偿周末和封闭市场中数据的缺乏。
How can I get a result that displays similar to a Yahoo Finance or Google Finance stock chart, where it ignores mising data ( as in this example ?我怎样才能得到一个类似于 Yahoo Finance 或 Google Finance 股票图表的结果,它忽略了丢失的数据(如本例所示?
Just use this.就用这个。 Done.
完毕。
import pandas as pd
import datetime
import pandas_datareader.data as web
start=datetime.datetime(2019,3,12)
end=datetime.datetime(2020,3,12)
df=web.DataReader('IBM','yahoo',start,end)
print(df)
Result:结果:
2020-01-30 135.356583
2020-01-31 142.244659
2020-02-03 144.758408
2020-02-04 147.569061
2020-02-05 154.714447
2020-02-06 155.139999
2020-02-07 153.410004
2020-02-10 154.429993
2020-02-11 153.479996
2020-02-12 155.309998
2020-02-13 154.309998
2020-02-14 150.699997
2020-02-18 151.100006
2020-02-19 150.860001
2020-02-20 151.220001
2020-02-21 149.839996
2020-02-24 146.429993
2020-02-25 141.710007
2020-02-26 139.750000
2020-02-27 133.110001
2020-02-28 130.149994
2020-03-02 134.300003
2020-03-03 128.899994
2020-03-04 134.220001
2020-03-05 129.550003
2020-03-06 127.730003
2020-03-09 117.809998
2020-03-10 124.769997
2020-03-11 117.970001
2020-03-12 102.809998
Check this out too.也检查一下。
https://pandas-datareader.readthedocs.io/en/latest/remote_data.html#quandl https://pandas-datareader.readthedocs.io/en/latest/remote_data.html#quandl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.