Error with stock screener: AttributeError: 'int' object has no attribute 'replace'
Error with stock screener: AttributeError: 'int' object has no attribute 'replace'
我正在使用替换函数来删除百分比,以便可以更轻松地将 to 转换为整数。另外,我想在数据中出现 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
不包含 "Return on Equity",您将使用整数 0 作为默认值,并且您不能对整数调用 replace()。
我正在使用替换函数来删除百分比,以便可以更轻松地将 to 转换为整数。另外,我想在数据中出现 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
不包含 "Return on Equity",您将使用整数 0 作为默认值,并且您不能对整数调用 replace()。