0

I am trying to get a dataframe in the format below into a txt file as shown in the screenshot.

I get relatively close with the code shown but get the following error when I tried to read the txt into my ML algorithm: "labels = set([label.value for sent in self.train for label in sent.labels]) AttributeError: 'NoneType' object has no attribute 'labels'"

Can anyone help?

output['label']=['__label__'+ s for s in output['label'].astype(str)]
output['text']= output['text'].replace('\n',' ', regex=True).replace('\t',' ', regex=True)
output.to_csv(r'sst_train.csv', index=False, sep=' ', header=False)

Input

Output

ms5573
  • 41
  • 5

1 Answers1

0

The below seems to work:

lab = data['label'].tolist()
text = data['text'].tolist()
with open('test.txt', 'w') as outfile:
    for x in range(len(lab)):
        l1 = str(lab[x])
        print(type(l1))
        t1 = str(text[x])
        print(t1)
        d = 'ewdwed'
        message = "__label__{}\t{}\n".format(l1,t1)
        outfile.write(message)
ms5573
  • 41
  • 5