from datasets import load_dataset import re ds = load_dataset("test.csv") def prepro(datapoint): pattern = "\s([0-9]\.){0,1}[0-9]{0,3}(?=\Z)" text = datapoint["Embedded_text"].replace("\n", " ") for i in range(3): text = re.sub(pattern, "", text) text = text.replace("Diesen Thread anzeigen", "").replace(" ", " ").replace(" ", " ") datapoint["text"] = text del datapoint["Embedded_text"] return datapoint ds_f = ds.map(prepro) ds_f.to_parquet("test.parquet")