1

I have a list of values which shall end up in a specific json format.

example input:

plate_list = "TestXX105,TestXX106"

example output:

plate_json = '[{"key": "plate1", "value": "TestXX103"}, {"key":
"plate2", "value": "TestXX104"}]'

I tried to generate a dataframe and transform it into a json, but the formatting never fit:

plate_Barcodes = pd.DataFrame()

plate_list = "TestXX105,TestXX106"
 
plate_count = "plate1,plate2"

plate_Barcodes["key"] = pd.Series(plate_count.split(","))
 
plate_Barcodes["value"] = pd.Series(plate_list.split(","))
 
result = plate_Barcodes.to_json(orient = "columns")

But the result always includes the index: {"key":{"0":"TestXX105","1":"TestXX106"},"value":{"0":"TestXX105","1":"TestXX106"}}

Do you have an idea, how I could receive my needed format?

0

1 Answer 1

0

Use orient = records instead.

plate_Barcodes.to_json(orient = "records")
#'[{"key":"plate1","value":"TestXX105"},{"key":"plate2","value":"TestXX106"}]'

You can read more about orient and the options -> outputs it provides in the docs.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.