I am currently working with CSV data that includes a column 'characteristic' with three types and a 'value' column containing the numerical values for each characteristic. I am looking to restructure this data so that each characteristic becomes a separate column and its corresponding values fall directly under it.
Here is an example of the current structure: https://i.sstatic.net/3R8eh.png
And this is the desired structure: https://i.sstatic.net/9dVHK.png
I manually changed the structure in the example, but the actual table is thousands of lines long, so I am looking for a way to programmatically achieve this restructuring.
The reason for this restructuring is that I want to convert the CSV data to JSON format, where each row will look like this:
[
{
"country":"afghanistan",
"iso3":"afg",
"first_indicator":3,
"second_indicator":5,
"third_indicator":3
},
{
"country":"united states",
"iso3":"usa",
"first_indicator":8,
"second_indicator":6,
"third_indicator":7
},
{
"country":"china",
"iso3":"chn",
"first_indicator":6,
"second_indicator":0.7,
"third_indicator":2
}
]
Is there a way to automatically transform my current CSV structure (as shown in the first screenshot) into the JSON format I need, without manual intervention? I have searched extensively but have not found a solution. I am open to suggestions, but ideally, I would like to use JavaScript for this task. Thank you.