Is there a better way to read in
- the name of a textfile and
- the content of a text file into a dataframe?
(Or is my implementation even okay?) Can I avoid storing the data in lists?
path =r'.../test_age7' allFiles = glob.glob(path + "/*.txt") df_7 = pd.DataFrame() # create empty DF stories =  filenames =  for file_ in allFiles: with open(file_) as f: textf = " ".join(line.strip() for line in f) stories.append(textf) filenames.append(os.path.basename(file_[0:-4])) # extract filename without .txt df_7["filename"] = filenames df_7["stories"] = stories df_7["age"] = path[-1]