【问题标题】:How can I make sure that dates display as in Yahoo Finance / Google Finance without accounting for weekends?在不考虑周末的情况下,如何确保日期显示为雅虎财经/谷歌财经?
【发布时间】:2020-06-15 02:43:55
【问题描述】:

我目前正在使用 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 compensates for the lack of data in weekends and at closed market 从一个数据点到另一个数据点画一条直线。

如何获得显示类似于 Yahoo Finance 或 Google Finance 股票图表的结果,它会忽略丢失的数据 (as in this example?

【问题讨论】:

    标签: python pandas matplotlib plot stock


    【解决方案1】:

    就用这个吧。完成。

    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

    【讨论】:

      猜你喜欢
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-10
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      相关资源
      最近更新 更多