Search code examples
swiftmacos-mojavecreateml

Can't access MLDataTable columns by name


I created a MLDataTable by reading in a CSV. When I print the MLDataTable, it appears to have column names.

Columns:

     data_id    integer
     iso    integer
     event_id_cnty  string
     event_id_no_cnty   integer
     ...

but when I try to access them it says there are no columns with those names

print(dataTable.columnTypes)
[:]
print(dataTable.columnNames)
[]

Solution

  • I figured it out. I tried to add a new column:

    dataTable.addColumn(column, named: "more_strings")
    

    it would failed with this error:

    generic(reason: "Column \\"more_strings\\" has different size than current columns!")
    

    but I continued on experimenting with the playground thinking that line wouldn't make a difference to the data already in the table. Apparently failing to add a column wipes out the table in Xcode 10.1 playgrounds. After I commented out the addColumn line I could access the columns by name.