简体   繁体   English

Indexerror:列出超出 excel 文件范围的索引

[英]Indexerror: list index out of range for excel file

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_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']

Anyone know the soultion to this?有人知道这个的灵魂吗?

nvm, I found the error. nvm,我发现了错误。 I was using read_excel instead of read_csv to read a csv file.我使用read_excel而不是read_csv来读取 csv 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM