【问题标题】:from the yfinance library how can I read the ex-dividend date?从 yfinance 图书馆我如何阅读除息日期?
【发布时间】:2022-10-02 20:09:08
【问题描述】:

此代码应返回除息日期:

import yfinance as yf

yf.Ticker(\'AGNC\').info[\'exDividendDate\']

但我得到这个作为输出: 1661817600

我想知道是否有办法从该号码中获取日期?

    标签: yfinance


    【解决方案1】:

    看起来这个数字是基于秒获得的。为了获得真实日期,您可以使用pd.to_datetime 将秒数转换为日历日期。

    import pandas as pd
    
    pd.to_datetime(1661817600, unit='s')
    Out[6]: Timestamp('2022-08-30 00:00:00')
    

    或者您可以使用 Python 中内置的 datetime 包。

    from datetime import datetime
    
    print(datetime.fromtimestamp(1661817600))
    2022-08-30 08:00:00
    

    【讨论】:

      【解决方案2】:

      从日期时间导入日期时间

      TCS=yf.Ticker('TCS.NS')

      时间戳 = TCS.info['exDividendDate']

      dt_obj = datetime.fromtimestamp(时间戳)

      print("除息日期:",dt_obj.date())

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-24
        • 2018-10-30
        • 2019-10-31
        • 1970-01-01
        相关资源
        最近更新 更多