簡體   English   中英

stock screener出錯:AttributeError:'int'對象沒有屬性'replace'

[英]Error with stock screener: AttributeError: 'int' object has no attribute 'replace'

我使用替換函數來擺脫百分比,以便更容易變成整數。 另外,我想在數據中出現N / A的情況下使用替換功能。

這是我試圖開發的股票篩選器,它通過一個股票列表,並根據我的標准給我剩余的股票。

def scrape(stock_list, interested, technicals):
    condition_1 = float(technicals.get('Return on Equity',0).replace("%","")) > 0
    condition_2 = float(technicals.get('Trailing P/E',0).replace("N/A","")) > 20
    for each_stock in stock_list:
        technicals = scrape_yahoo(each_stock)

        if condition_1 and condition_2:
            print(each_stock)
            for ind in interested:
                print(ind + ": "+ technicals[ind])
            print("------")
            time.sleep(1)                                                    # Use delay to avoid getting flagged as bot
    return technicals
def main():
    stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD']
    interested = ['Trailing P/E', 'Return on Equity', 'Revenue', 'Quarterly Revenue Growth']
    technicals = {}
    tech = scrape(stock_list, interested, technicals)
    print(tech)


main()

AttributeError:'int'對象沒有屬性'replace'

technicals.get('Return on Equity',0).replace("%","")

如果technicals不包含“股本回報率”,則使用整數0作為默認值,並且不能對整數調用replace()。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM