Grabbing one full row out of a table as a dataset?

I have a window that accepts a dataset as a parameter that comes from a parent window. Previously this was calculated by running a query, but there must be a way to get that full row as a dataset. How can I do that?

For instance, I have a table with a bound sql data query, and I want to get the 5th row as it’s own dataset.

Answer for anyone else seeking a solution, what I came up with

def getRow(data, row):
	"""
	Input table data and row you want to get a dataset from
	Args:
		data: Dataset, ususally table.data, but works with other datasets as well
		row: int, what row do you want?
	Returns:
		dataset: 1R x MC, where M is the number of columns in the datset
	"""
	import system.dataset
	
	columns = map(str,data.columnNames)
	values = []
	for col in data.columnNames:
		values.append(data.getValueAt(row, col))
	return system.dataset.toDataSet(columns, [values])

Why do I map the str to the data.columnNames? Because system.dataset didn’t like it otherwise. Not sure why. But this works.

data.columnNames is a string array on the Java side, but the system.dataset.toDataSet function requires a list of strings. You could also just list(data.columnNames) to do the appropriate conversion.

You could also write your function with system.dataset.deleteRows

def getRow(data, row):
	"""
	Input table data and row you want to get a dataset from
	Args:
		data: Dataset, ususally table.data, but works with other datasets as well
		row: int, what row do you want?
	Returns:
		dataset: 1R x MC, where M is the number of columns in the datset
	"""
	return system.dataset.deleteRows(data, [i for i in xrange(data.rowCount) if i != row])
2 Likes