Add column to a dataset

Good afternoon,
I need a column to a dataset.
The type of column is java.lang.String
When I use this function:

system.dataset.addColumn(dataset_dosati_generale, system.dataset.toPyDataSet(dataset_inerte_2_dosato) , "dosato", str)

I have this error:

Traceback (most recent call last):
  File "<event:mouseReleased>", line 52, in <module>
TypeError: can't convert [u'0'] to java.lang.String



I don't understand why

Those brackets suggest you are supplying an extra layer of listification. Please show your code.

this is the code:

dataset_inerte_2_dosato= system.dataset.filterColumns(dataset_dosati, ["qta_dosata"])

ds2 = system.dataset.addColumn(dataset_dosati_generale, system.dataset.toPyDataSet(dataset_inerte_2_dosato) , "dosato", str)

dataset_inerte_2_dosato= system.dataset.filterColumns(dataset_dosati, ["qta_dosata"])

Try with this instead:
dataset_inerte_2_dosato = dataset_dosati.getColumnAsList(dataset_dosati.getColumnIndex("qta_dosata"))

This function work well:

dataset_inerte_2_dosato= dataset_dosati.getColumnAsList(dataset_dosati.getColumnIndex("qta_dosata"))

After, with this function:

ds2 = system.dataset.addColumn( dataset_dosati_generale, dataset_inerte_2_dosato , "qta_dosata", str)

I have this error:

TypeError: addColumn(): 2nd arg can't be coerced to org.python.core.PySequence

Why???

Thank you

well... Seems explicit enough. addColumn needs a pySequence, and what you're passing isn't one.

Why does this happen ? getColumnAsList returns a java.util.ArrayList. I agree, it's painful that addColumn can't take this type... but the solution is quite simple: just wrap your column in a list() call:

ds2 = system.dataset.addColumn(dataset_dosati_generale, list(dataset_inerte_2_dosato), "qta_dosata", str)
1 Like