i'd stacked append each file using pandas.
i have daily directory , each directory has same name file.
here example.
- api.log,click.log,id.log in 20150401 directory.
- api.log,click.log,id.log in 20150402 directory.
- api.log,click.log,id.log in 20150403 directory.
- api.log,click.log,id.log in 20150404 directory.
i wanna gather api.log 1 dataframe.
import os pandas import dataframe import pandas pd dir_list = ['20150401','20150402','20150403','20150404'] counter = 0 var_box = pd.dataframe() dir_date in dir_list: next_path = current_path+"/"+dir_date os.chdir(next_path) df = pd.read_csv('api.log',sep="\t",names=['date_time','param','oid','url'],na_values=['null']) try: if counter == 0: var_box2 = var_box.append(df) counter += 1 else: var_box3= var_box2.append(df) counter += 1 except exception e: print e.message print(var_box3)
i've checked result,but var_box3 doesn't have each api.log files.
thanks reading
what's counter? did forget in loop?
the main issue here append returns none:
var_box2 = var_box.append(df)
and none has no append method, raise attributeerror:
var_box3 = var_box2.append(df)
which caught exception, , ignored.
generally want avoid catching exception includes problem e.g. if ctrl+c end process (this caught).
i think want here, make 1 frame several, concat:
pd.concat(var_box)