I have a folder called Contracts and then in that folder I have folders for several companies. In the company folders I have several contracts that we have with those companies. I am trying to get a data frame that has two columns, Folder_Name and Contract.
I tried to follow this question, Python list directory, subdirectory, and files which got me close, I think, but I could not get a column with the folder name that the contract was from.
I thought this would work:
import pathlib, sys, os
import pandas as pd
cwd = os.getcwd()
lst1 = []
lst2 = []
for path, subdir, file in os.walk(cwd):
for i in subdir:
for name in file:
lst1.append(i)
lst2.append(name)
df = pd.DataFrame(zip(lst1, lst2), columns = ['Folder_Name', 'Contract'])
but it only gave me the folder names in one column and the names of files in the contracts folder instead of in the company folders
Folder_Name Contract
0 .ipynb_checkpoints Untitled.ipynb
1 AWS Untitled.ipynb