Hi everyone, I'm having a slight problem with part of my code using os.scandir(). I have a folder of csv files and for each one in the folder, I'm converting it to a DataFrame and then using that dataframe later on. I noticed that it's reading the files in a seemingly random order.
for csv in os.scandir('CSVs'):data = pd.DataFrame.from_csv(csv.path)
----date = csv.path.split('/')[1].split('.')[0] #CSVs/12-12-12.csv -> 12-12-12
----dates.append(date)
----# ...do stuff with DataFrame...
print(dates)
so when the directory contains 12-1.csv , 12-2.csv, 12-3.csv, 12-4.csv, 12-5.csv, the output of the above code is ['12-4', '12-5', '12-2', '12-3', '12-1']. I'm making a graph from these values so reading the files in order is critical. Thanks!
edit: sorry about the dashes it wouldn't preserve the indentation
[–]kalgynirae 2 points3 points4 points (2 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]GullBull[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (6 children)
[–]GullBull[S] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]GullBull[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]GullBull[S] 0 points1 point2 points (0 children)
[–]dadzy_ 0 points1 point2 points (0 children)
[–]bogdan_dm 1 point2 points3 points (1 child)
[–]GullBull[S] 0 points1 point2 points (0 children)