Convert Pandas dataframe to jsonl

Hi guys,

I have a table that looks like this

Feedback

content 1
content 2
content 3

How do I convert this to the jsonl in this format using pandas:
{text: content 1}
{text:content 2}

as required by the specialized endpoints. A step by step example would be highly appreciated!

Please note that the correct format is as follows:
{"text": "content 1"}

You can try the following:
df.to_json(jsonlfilename, orient=“records”, lines=True)

1 Like

Hi, thanks for responding.

I tried that code but the problem is instead of what we want it to do it’s actually converting it into this format:

“content 1”, “content 2”, “content 3”,…

So how can I add it into dict with the text key.

Can you clarify your input and the code you’re trying? What @joey suggested works fine for me.

hi I figured it out!

The problem was I was using that code on Series Object type. It works on DataFrame object only.

just in case if you’re wondering how to convert Series to Dataframe you can use the code
df.to_frame(name=“new column name”)

Thanks for sharing! For clarity, it may be helpful to note that “df” does not refer to DataFrame in this case, as you’re converting to a DataFrame. Instead, we can think of it as:
series.to_frame(name=“new column name”)

1 Like