我试图打开多个excel文件。我的程序抛出错误消息“FileNotFoundError”。该文件存在于目录中。在
代码如下:
import os
import pandas as pd
path = "C:\\GPA Calculations for CSM\\twentyfourteen"
files = os.listdir(path)
print (files)
df = pd.DataFrame()
for f in files:
df = pd.read_excel(f,'Internal', skiprows = 7)
print ("file name is " + f)
print (df.loc[0][1])
print (df.loc[1][1])
print (df.loc[2][1])
程序在df = pd.read_excel(f,'Internal', skiprows = 7)
上出错。在
我在另一个程序上打开了同一个文件(只打开一个文件),效果很好。如有任何建议或建议,我们将不胜感激。在
os.listdir
列出作为参数的相对于目录(路径)的文件名。因此,您需要将路径和文件名连接在一起,以获得每个文件的绝对路径。因此,在循环中:相关问题 更多 >
编程相关推荐