[英]Read dataframes from files of different subfolders
I have 12 different directories, looking something like that: 我有12个不同的目录,看起来像这样:
directories = ['FOLDER/subfolder01/*.csv', 'FOLDER/subfolder02/*csv', ... ]
12 subfolders within one major FOLDER, each one containing a set of csv files with the same data format. 一个主要文件夹中的12个子文件夹,每个子文件夹包含一组具有相同数据格式的csv文件。
I'd like to loop over it and somehow read the dataframes within each subfolder and then continue with the plots. 我想遍历它,以某种方式读取每个子文件夹中的数据框,然后继续进行绘制。
Is there a way to set the subfolders as indexes over which I can manipulate with the files? 有没有一种方法可以将子文件夹设置为可以使用文件操作的索引?
from glob import glob
directory_dfs = {directory_name: load_csvs_from_directory(directory_name)
for directory_name in glob('FOLDER/subfolder*/')}
Then just encapsulate your logic for how to read all the CSV's from a directory into the load_csvs_from_directory
function, and voila, you have a labelled collection of the DataFrames built from the data in each directory. 然后,只需封装有关如何从目录中读取所有CSV的逻辑到
load_csvs_from_directory
函数中,瞧,您就有从每个目录中的数据构建的带标签的DataFrame集合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.