【发布时间】:2019-12-14 14:42:43
【问题描述】:
我的 CSV 文件在目录中按以下方式排序:
index_dc_20090131
index_dc_20090228
index_dc_20090331
index_dc_20090430
index_dc_20090531
index_dc_20090630
我正在通过以下方式阅读我的 csv 文件:
path = r'myDirectory'
all_files = glob.glob(path + "/*.csv")
li = []
for filename in all_files:
frame = pd.read_csv(filename, index_col = None, header = 0, sep = ";")
li.append(frame)
我假设li 将按照与上述相同的顺序存储文件,但显然这是一个完全随机的顺序。显然,它与文件的名称或大小或它们包含的列数无关。
如何读取 CSV 文件以使它们与我的目录中的顺序相同?我想避免重命名我的文件。
【问题讨论】: