df = pd.read_table(filedata, delim_whitespace=True, names={'X','Y','Z'})
this line replace df
at each iteration of the loop, that's why you only have the last one at the end of your program.
what you can do is to save all your dataframe in a list and concatenate them at the end
df_list = []
for file in file_list:
try:
if fnmatch.fnmatch(file, '*.txt'):
filedata = open(file, 'r')
df_list.append(pd.read_table(filedata, delim_whitespace=True, names={'X','Y','Z'}))
df = pd.concat(df_list)
alternatively, you can write it:
df_list = pd.concat([pd.read_table(open(file, 'r'), delim_whitespace=True, names={'X','Y','Z'}) for file in file_list if fnmatch.fnmatch(file, '*.txt')])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…