If you do print filename in the for loop #commented below, it gives you all the file names in the directory. yet when I call pd.ExcelFile(filename) it returns that there is no file with the name of : [the first file that ends with '.xlsx' What am I missing? p.s: the indentation below is right, the if is under the for in my code, but it doesn't show this way here..
for filename in os.listdir('/Users/ramikhoury/PycharmProjects/R/excel_files'):
if filename.endswith(".xlsx"):
month = pd.ExcelFile(filename)
day_list = month.sheet_names
i = 0
for day in month.sheet_names:
df = pd.read_excel(month, sheet_name=day, skiprows=21)
df = df.iloc[:, 1:]
df = df[[df.columns[0], df.columns[4], df.columns[8]]]
df = df.iloc[1:16]
df['Date'] = day
df = df.set_index('Date')
day_list[i] = df
i += 1
month_frame = day_list[0]
x = 1
while x < len(day_list):
month_frame = pd.concat([month_frame, day_list[x]])
x += 1
print filename + ' created the following dataframe: \n'
print month_frame # month_frame is the combination of the all the sheets inside the file in one dataframe !