7

my folder organization looks like below. Type 1 and Type 2 folders contains same files but I want to only read the files from 'type 2' folder. Is there any simple way to do that?

I have used this code but not able to read:

for file in os.listdir('Type 2'):
    print file

folder organization

your help will be highly appreciated!

1 Answer 1

12

IIUC you need read_csv in folders Type 2, use glob:

files = glob.glob('main/**/Type 2/*.csv')
dfs = [pd.read_csv(fp) for fp in files]
df = pd.concat(dfs)
Sign up to request clarification or add additional context in comments.

3 Comments

i got this error while reading.. glob() got an unexpected keyword argument 'recursive'
try remove it, solution is untested yet.
yes that might be the problems, now I am using 2.7.0 , but when I remove recursive it works perfectly :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.