I made a code that reads a series of CSV files within a folder. It reads all of the CSV files within a folder that I select. The CSV files are formatted like:
A1.CSV, A2.CSV, A3.CSV, ...., A10.CSV, A11.CSV, ..... A24.CSV, B1.CSV, B2.CSV, ...
and so forth.
The code reads the files and then appends them column-wise. However, when it reads the files, the order becomes: A1 > A10 > A11 > ... > A19 > A2 > A20 > A21 ...
Is there a way to make python read the files in alpha-numerical order like: A1 > A2 > A3 > ... > A10 > A11 >...
I can manually add zeroes to single digits (like A01), which is tedious as I have many files with single digits after an alphabet.
for files in os.listdir(full_path):
if os.path.isfile(os.path.join(full_path, files)):
df = pd.read_excel(files, 'Sheet1')[pkitems]
df[''] = np.nan
dfs.append(df)
data = pd.concat(dfs, axis=1)