Order in which files are read using os.listdir?

As per documentation: "The list is in arbitrary order"

https://docs.python.org/3.6/library/os.html#os.listdir

If you wish to establish an order (alphabetical in this case), you could sort it.

import os
for file in sorted(os.listdir(path)):
    df = pd.read_csv(path+file)
    // do stuff

You asked several questions:

  • Is there an order in which Python loops through the files?

No, Python does not impose any predictable order. The docs say 'The list is in arbitrary order'. If order matters, you must impose it. Practically speaking, the files are returned in the same order used by the underlying operating system, but one mustn't rely on that.

  • Is it alphabetical?

Probably not. But even if it were you mustn't rely upon that. (See above).

  • How could I establish an order?

for file in sorted(os.listdir(path)):