[英]How can I make sure that dates display as in Yahoo Finance / Google Finance without accounting for weekends?
我目前正在使用 Alpha-Vantage 以 1 分鍾的間隔獲取財務數據。
amd=ts.get_intraday(symbol=symbol, outputsize='full', interval=interval)
amd=pd.DataFrame(amd[0])
amd.drop(amd.index[-1])
我得到以下輸出
...
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
...
如您所見,日期從 2 月 28 日跳到了 3 月 2 日,這是理所當然的。 但是,在 matplotlib 中繪制時...
amd['4. close'].plot()
plt.title('AMD')
plt.show()
...我得到了下圖,其中mathplotlib通過從一個數據點到另一個數據點繪制一條直線來補償周末和封閉市場中數據的缺乏。
我怎樣才能得到一個類似於 Yahoo Finance 或 Google Finance 股票圖表的結果,它忽略了丟失的數據(如本例所示?
就用這個。 完畢。
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)
結果:
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
也檢查一下。
https://pandas-datareader.readthedocs.io/en/latest/remote_data.html#quandl
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.