我正在尝试从os.walk()
. 这是我的文件夹结构的示例。
Top Folder1
---File1
Top Folder2
---File2
---File3
---File4
我想像这样制作一个DataFrame:
Path File_Name
0 Folder1_Path File1
1 Folder2_Path File2
2 Folder2_Path File3
3 Folder2_Path File4
我可以获得文件夹的路径和文件名,但我找不到将它们组合成数据框的方法。我尝试过concat
进入append
空 DataFrame 无济于事,甚至尝试创建多个Series
并将它们放入单个 DataFrame 中。
import pandas as pd
import os
import os.path
for root,dirs,files in os.walk('Y:\\', topdown=True):
if len(files) > 0:
print(root) #Gets the Folder Path
print("---", files) #Creates a List of the files
如何root
在 DataFrame 的一列和files
另一列中获得?