pandas - 即使有股票数据,如何用 pandas 和 excel 解决关键错误 5?
问题描述
我在 python 中有以下代码作为股票筛选器。
import pandas as pd
import numpy as np
import yfinance as yf
import datetime as dt
from pandas_datareader import data as pdr
import os
from pandas import ExcelWriter
yf.pdr_override()#takes new changes in python into consideration
start = dt.datetime(2015,1,1)
now = dt.datetime.now()
ftypes = [(".xlsm","*.xlsx",".xls")]
filePath = r'C:\Users\Yatharth K\Desktop\n.xlsx'
stocklist = pd.read_excel(filePath)
stocklist = stocklist.head()
stocklist=stocklist.sort_index()
for i in range(0,50):
try:
stock = str(stocklist["Symbol"][i])
df = pdr.get_data_yahoo(stock,start,now)
dfmonth = df.groupby(pd.Grouper(freq = "M"))["High"].max()
glDate = 0
lastGLV = 0
currentDate = ""
currentGLV = 0
for index, value in dfmonth.items():
if(value>currentGLV):
currentGLV = value
currentDate = index
counter = 0
if(value<currentGLV):
counter = counter + 1
if(counter == 3 and ((index.month != now.month) or (index.year != now.year))):
glDate = currentDate
lastGLV = currentGLV
counter = 0
over = now - glDate
if(over.days <= 35 and lastGLV != 0):
final.append("Ticker: " + str(stock + " " + str(lastGLV) + ": " + str(glDate)))
except:
print("No data")
我的 excel 文件在这里:https ://www.nasdaq.com/market-activity/stocks/screener 。我已经多次检查链接并且它有效。但我不断收到一个关键错误 5。有人说可能没有任何可用的股票数据,但我检查了 yahoo Finance pandas 数据阅读器,即使它们产生错误,我也可以访问大部分股票。我添加了一个 except 来消除错误,但它仍然没有解决问题。请帮忙。谢谢。
解决方案
推荐阅读
- flutter - SingleChildScrollView 内的颤振列不滚动
- python - 如何在 openCV 视频中放置标准过滤器?
- php - 如何从另一个 .php 文件调用 .php 文件
- python - Python Reddit API 将 gifv 转换为可读的 mp4
- java - 使用 activityForResult 后用户数据未插入到 recyclerView
- php - 子数组中带有“max”字段的 MongoDB 聚合“组”
- mysql - 是否可以在存储过程中创建具有可选数据类型的新列?
- python - 获取 Firebase 查询状态 Pyrebase
- tensorflow.js - 是否可以使用多个权重文件加载 tensorflow js 模型?
- pine-script - 通过脚本而不是通过添加指标功能将 EMA 放入 RSI 指标?