Best way to remove a column from a json dataset

I have a dataset like this:

[
{"VALUE1":"","VALUE2":""...},
{"VALUE1":"","VALUE2":""...},
{"VALUE1":"","VALUE2":""...},
]

What is the best way of removing a column?

[i.pop("VALUE1") for i in dataset]
or

#pseudo-code
dataset = system.dataset.toDataSet(headers, data)
dataset = system.dataset.filterColumns(!"VALUE2")
dataset = to.json.dataset(dataset)

FYI: wanna delete that column only if is entirely empty (that's my current objective).

Thanks for the help!

Ended up doing this:

if not any([i.get("VALUE2") for i in value]):
	value = [i.pop("VALUE2") for i in value]

Note that this is an inherently inefficient operation that's burning a lot of CPU to run through the list of rows ~twice. Depending on what else you need to do with this data, it might be worth reorganizing to have a single list-per-column in a dictionary per column name, and only 'translate' to this row-wise data structure at the end.

I thought about that, but I ended doing something a bit different.

I used this:

And did this:

self.props.columns[6].visible = any(value.getColumnAsList(value.getColumnIndex("VALUE2")))

So only I show it if there is something to show. A bit different approach than what I first thought. Also this only gets executed at the start of the view. So even if it's a bit inefficient is only done 1 time.

This sound like an XY problem

3 Likes