python - Concatenate multiple similar CSV files into one big dataframe -


i have 1 directory there csv files want use. want concatenate these csv files , create bigger one. i've tried 1 code didn't work.

import os import pandas pd  targetdir = r'c:/users/toshiba/documents/icf2011/base admision san marcos 2014-2/sabado'  filelist = os.listdir(targetdir)   big_df=pd.dataframe() file in filelist :     big_df.append(pd.read_csv(file), ignore_index=true) 

i run code , there's message says: ioerror: file a011.csv not exist. contradictory because a011.csv first csv file in directory used.

listdir returns filename, not complete path. complete path need join targetdir , file (bad variable name masks file type). also, have capture result of .append returns new object rather appending in place.

for filename in filelist:     big_df = big_df.append(pd.read_csv(os.path.join(targetdir, filename), ignore_index=true) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -