【发布时间】:2021-07-14 12:19:00
【问题描述】:
有没有办法导入文件夹 1 中的所有文件?每个 csv 文件都包含在一个子文件夹中。下面是文件结构。
C:/downloads/folder1 > tree /F
C:.
│ tree
│
├───2020-06
│ test1.csv
│
├───2020-07
│ test2.csv
│
├───2020-08
│ test3.csv
│
├───2020-09
│ test4.csv
我知道下面的 glob 可以获取文件夹中的所有文件。但是这可以用于子文件夹吗?
import glob
import pandas as pd
# Get a list of all the csv files
csv_files = glob.____('*.csv')
# List comprehension that loads of all the files
dfs = [pd.read_csv(____) for ____ in ____]
# List comprehension that looks at the shape of all DataFrames
print(____)
【问题讨论】: