import pandas as pd def flatten(t): return [item for sublist in t for item in sublist] def getData(): Xdata = [] Ydata = [] pathOut = './tasks/zad8/pl/' pathIn = "./data/clean/" i = 0 j = 0 nr = 0 for i in range(16,20): for j in range(20): for nr in range(1,5): fileName = pathIn + "dialog-" + str(i).zfill(2) + "-" + str(j).zfill(2) + "-" + str(nr).zfill(2) + ".tsv" try: df = pd.read_csv(fileName, sep='\t', header=None, encoding="utf-8") Xdata.append(df[1].tolist()) Ydata.append(df[2].tolist()) except: pass return flatten(Xdata), flatten(Ydata) x,y = getData() print(y)