I am in need of help, I have a dataset that i need to make a json.
This is the dataset:
How can i convert it to a json so i can parse column data?
I am in need of help, I have a dataset that i need to make a json.
This is the dataset:
How can i convert it to a json so i can parse column data?
Thank you sir
Anyway I can insert rows into this? I would like to add Denier rows with names in the column. Then have a Doff_Number default value of 0 on each row, then when something in that row it replaces that 0 with a value?
columnnames = [
{
'Doff_Number':Doff_Number,
'Denier':Denier,
} for Doff_Number,Denier in system.dataset.toPyDataSet(value)
]
return columnnames
So it would resemble something like this:
Then if only the 1385 row had doff_number data it will fill it in but leave the rest at 0, like this:
columnnames = [
{
'Doff_Number':Doff_Number if Doff_Number else 0,
'Denier':Denier,
} for Doff_Number,Denier in system.dataset.toPyDataSet(value)
]
return columnnames
I think this will get you what youâre looking for, but itâs sort of dangerous depending on the type of the column.
For example, if Doff_Number
is a string column, and a row contains a value of "0"
in that column, then youâll get String â0â instead of 0
because bool("0")
equates to True
. So you need to be aware of what type a given column is.
Just for posterity, below is useable for converting any dataset into a json object Py objects. Of course, it doesn't provide the extra condition in the OP, but this could be added with an if
pds = system.dataset.toPyDataSet(value)
columnNames = pds.columnNames
ret = [
{
col: row[col]
for col in columnNames
} for row in pds
]
return ret
this worked like a charm. thanks!