Add 2 dataset values and put in single dataset

Hi i am getting selected tags in list… so its easy for me to run for loop

then you should have no problem implementing what i just send^^

1 Like

@prasath.t is appending his queries into a single dataset. That actually simplifies things.
EDIT: added functionality to use None if all values in a cloumn are None.

sampleHeaders = ['date','elec','gas']
sampleData = [
              ['2021-11-23 00:00:00',   None, 40],
              ['2021-11-23 00:00:00',   24,   90],
              ['2021-11-23 00:00:00',   89, None]

# Simulate the dataset used to gather the data
data = system.dataset.toDataSet(sampleHeaders, sampleData)

# Set allowed types  --java.lang class names--
allowedTypes = ['Long', 'Integer', 'Double', 'Float']

# Get column names
colNames = list(data.getColumnNames())
dataOut = []

for colNum in range(data.getColumnCount()):
#	print colNum, colNames[colNum], data.getColumnType(colNum).__name__
	# Check that the column is one that should be summed
	if data.getColumnType(colNum).__name__ in allowedTypes:
		# Get column values
		colValues = data.getColumnAsList(colNum)
		#Use None if all values in the list are None
		if all(value is None for value in colValues):
			# Sum the values and add to the row. filter() lets us ignore None
			dataOut.append(sum(filter(None, colValues)))
	# Otherwise, use the first row value
		dataOut.append(data.getValueAt(0, colNum))

datasetOut = system.dataset.toDataSet(colNames, [dataOut])
row | date                | elec | gas
0   | 2021-11-23 00:00:00 | 113  | 130
1 Like

Hi @JordanCClark

I tired your script but i am not getting the actual output. Please check the screenshot i have attached.
None values of 2 dataset added in your script i am getting 0 zero as output… but i want to return none

only i want to return integer value if one row have value other row have none value

Please give me solution for this one

hi @victordcq
Tired your script but got error

d1 = system.dataset.toDataSet(["1","2","3","4"],[[10,None,None,40]])
d2 = system.dataset.toDataSet(["1","2","3","4"],[[60,70,80,90]])

given 2 datset like this with none value in integer Column


columnData = [int(unicode) for unicode in AllRow.getColumnAsList(AllRow.getColumnIndex(col))]

getting error in this line

i am getting none value in integer column while doing query

ups right

columnData = [int(unicode or 0) for unicode in AllRow.getColumnAsList(AllRow.getColumnIndex(col))]

this will replace the none with 0, i suppose the filter later isnt needed anymore then if you care for the tiny performance
d3 = system.dataset.setValue(d3,0,col,sum(columnData))

d1 = system.dataset.toDataSet(["1","2","3","4"],[[10,None,None,40]])
d2 = system.dataset.toDataSet(["1","2","3","4"],[[60,44,None,90]])

for example - if both dataset of column 3 has none … so i want to return none to new dataset … i don’t want to get 0 zero as value

is it possible?

not like this no you would have to put in a different check to see if all data in the column is none
with any() or all() and i guess

if any(x == None for x in AllRow.getColumnAsList(AllRow.getColumnIndex(col))):
 d3 = system.dataset.setValue(d3,0,col,None)

Ok i will try this

in which line i have to use this script in your code ?

Edit elif probably isnt gona work afterall just use an if after i guess

if all(x == None for x in AllRow.getColumnAsList(AllRow.getColumnIndex(col))):
 d3 = system.dataset.setValue(d3,0,col,None)
1 Like
selectedDatasets =[[[10, 20, None, None]], [[10, 20, None, 40]]]

d3 = system.dataset.toDataSet(d1.getColumnNames().toArray(),[[0] * d1.getColumnCount()])
AllRow = system.dataset.toDataSet(d1.getColumnNames().toArray(),[])
for x in selectedDatasets:
	AllRow = system.dataset.addRow(AllRow, x[0])	
	for col in AllRow.getColumnNames():
		if col != "2":	
			if any(x == None for x in AllRow.getColumnAsList(AllRow.getColumnIndex(col))):
				print '...dd..'
				d3 = system.dataset.setValue(d3,0,col,None)
				columnData = [int(unicode or 0) for unicode in AllRow.getColumnAsList(AllRow.getColumnIndex(col))] 	
				d3 = system.dataset.setValue(d3,0,col,sum(columnData))
			d3 = system.dataset.setValue(d3,0,col,AllRow.getValueAt(0,col))	
print d3.getValueAt(0,3)

tried like this but column 4 of first dataset has None and column 4 second dataset have value 40
but its returning None… instead of 40

if condition should execute only all rows have none value

any correction to be done to make it work?

any should be all . i had already edited my code but seems you missed it

1 Like

thanks now its fine