0

I'm using pycharm and trying to iterate over a Directory that contains two folders with excel sheets inside each one and I'm always receiving this error message. Could you help me please?

path = '/Users/Henrique/Desktop/Rota Brasil Geral'

for x in os.listdir(path):
    if not x.startswith("."):
        for y in os.listdir(os.path.join(path, x)):
            if not y.startswith("."):
                file_path = (os.path.join(path, x, y))

                rod_merged = pd.read_excel(file_path, header=[0])
                extract_state = str(rod_merged.iloc[[], [0]])
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Madronos
  • 1
  • 1

1 Answers1

0

Just use glob, it's safer. Alternately you could use os.walk or scandir.walk to iterate through an find files.

import glob
path = '/Users/Henrique/Desktop/Rota Brasil Geral'

for file_path in glob.glob(path + '*.*'):
    rod_merged = pd.read_excel(file_path, header=[0])
    extract_state = str(rod_merged.iloc[[], [0]])
Amos Baker
  • 769
  • 6
  • 13