I am trying to read a bunch of csv files using glob in python. I want to read all the files in ascending order and then assign the data from each file to a different array.
My code right now looks like this:
for idx, f in enumerate (glob.glob(os.path.join(gen_path, "*.csv"))):
data[idx] = pd.read_csv(f, index_col=False)
Can anyone help read the files in a sorted way.
Thanks.
glob
returns a list of strings. Just sort it.
for idx, f in enumerate(sorted(glob.glob(os.path.join(gen_path,"*.csv")))):
```
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.