indexError:列表索引范围超出excel文件的范围
我要运行这件代码:
import glob
filenames=list(glob.glob("../Data/atp_data.csv"))
l = [pd.read_excel(filename,encoding='latin-1') for filename in filenames]
no_b365=[i for i,d in enumerate(l) if "B365W" not in l[i].columns]
no_pi=[i for i,d in enumerate(l) if "PSW" not in l[i].columns]
for i in no_pi:
l[i]["PSW"]=np.nan
l[i]["PSL"]=np.nan
for i in no_b365:
l[i]["B365W"]=np.nan
l[i]["B365L"]=np.nan
l=[d[list(d.columns)[:13]+["Wsets","Lsets","Comment"]+["PSW","PSL","B365W","B365L"]] for d in [l[0]]+l[2:]]
data=pd.concat(l,0)
每当我这样做时,我都会遇到此错误:
indexerror: list index out of range
以下是提到的atp_data.csv
文件中的列列表:
['ATP', 'Location', 'Tournament', 'Date', 'Series', 'Court', 'Surface', 'Round', 'Best of', 'Winner', 'Loser', 'WRank', 'LRank', 'WPts', 'LPts', 'W1', 'L1', 'W2', 'L2', 'W3', 'L3', 'W4', 'L4', 'W5', 'L5', 'Wsets', 'Lsets', 'Comment', 'B365W', 'B365L', 'CBW', 'CBL', 'EXW', 'EXL', 'IWW', 'IWL', 'PSW', 'PSL', 'MaxW', 'MaxL', 'AvgW', 'AvgL']
任何人都知道对此的灵魂?
I have this piece of code i am trying to run :
import glob
filenames=list(glob.glob("../Data/atp_data.csv"))
l = [pd.read_excel(filename,encoding='latin-1') for filename in filenames]
no_b365=[i for i,d in enumerate(l) if "B365W" not in l[i].columns]
no_pi=[i for i,d in enumerate(l) if "PSW" not in l[i].columns]
for i in no_pi:
l[i]["PSW"]=np.nan
l[i]["PSL"]=np.nan
for i in no_b365:
l[i]["B365W"]=np.nan
l[i]["B365L"]=np.nan
l=[d[list(d.columns)[:13]+["Wsets","Lsets","Comment"]+["PSW","PSL","B365W","B365L"]] for d in [l[0]]+l[2:]]
data=pd.concat(l,0)
Everytime i do however, i am getting this error:
indexerror: list index out of range
Here are the list of columns in the mentioned atp_data.csv
file:
['ATP', 'Location', 'Tournament', 'Date', 'Series', 'Court', 'Surface', 'Round', 'Best of', 'Winner', 'Loser', 'WRank', 'LRank', 'WPts', 'LPts', 'W1', 'L1', 'W2', 'L2', 'W3', 'L3', 'W4', 'L4', 'W5', 'L5', 'Wsets', 'Lsets', 'Comment', 'B365W', 'B365L', 'CBW', 'CBL', 'EXW', 'EXL', 'IWW', 'IWL', 'PSW', 'PSL', 'MaxW', 'MaxL', 'AvgW', 'AvgL']
Anyone know the soultion to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NVM,我发现了错误。我正在使用
read_excel
而不是read_csv
来读取CSV文件。nvm, I found the error. I was using
read_excel
instead ofread_csv
to read a csv file.