Исправить перечисление при генерации jsonl файла
Я хочу сохранить предсказания в Pandas DataFrame в jsonl файле, но при обращении к predictions выводит ошибку. Каким образом мне надо поменять обращение к predictions['target']
test_enum = pd.DataFrame([json.loads(x) for x in open('/content/test.jsonl').readlines()])
print(test_enum.shape)
test_enum.head()
(5095, 3)
idx premise hypothesis
0 0 Альбертозавр и другие тираннозавриды были разн... Альбертозавр и другие тираннозавриды были разн.
predictions = pd.DataFrame(np.round(np.clip(regressor.predict(_test), 0, 1)), columns=["target"])
target
0 0
1 1
2 0
3 1
5095 rows × 1 columns
with open('sabmission3.jsonl', 'w',encoding = 'utf-8') as f:
for i, idx in enumerate(test_enum.idx):
ans = {'idx' : idx, 'label': predictions['target'].replace('0','not_entailment').replace('1','entailment')}
f.write(json.dumps(ans)+'\n')
178 """
--> 179 raise TypeError(f'Object of type {o.__class__.__name__} '
180 f'is not JSON serializable')
181
TypeError: Object of type Series is not JSON serializable