Emil
Emil

Reputation: 1722

Export text file with custom extension Python

For a project working with Prodigy, I want to have a .jsonl file, in which each line is a json file.

To do so, I have the following code:

df['json'] = df.to_json(orient='records', lines=True).splitlines()

jsonl = ""

for js in df['json']:
    jsonl += js + '\n'

How can I export this text to the following name/directory:

DIRECTORY/texts.jsonl

Upvotes: 0

Views: 93

Answers (1)

daten-kieker
daten-kieker

Reputation: 115

You solved the hard part. You can write jsonl directly to a file:

with open("DIRECTORY/texts.jsonl", "w") as f:
    f.write(jsonl)

Upvotes: 1

Related Questions