I recently ran into this problem as well, especially when the need arises to append a whole new column with data from an entirely different source. Suppose, for example, that we have:
data = {<|"col1"->1,"col2"->2|>,<|"col1"->3,"col2"->4|>,<|"col1"->5,"col2"->6|>}; ds = Dataset[data] and that we also have a list with new data:
newdata = {3.14, 2.718, 1.618}; To add the new data as a column named "col3" to the dataset, I came up with a method based on transposing the dataset (it's interesting to note that Datasets that consist of lists of associations can be transposed, but ordinary lists of associations cannot):
addColumnToDataset[dataset_Dataset, column : _List, columnName : _String] /; Length[column] === Length[dataset] := addColumnToDataset[dataset, {column}, {columnName}]; addColumnToDataset[dataset_Dataset, columns : {__List}, columnNames : {__String}] /; And[ Length[columnNames] === Length[columns], Length[dataset] === Dimensions[columns][[2]] ] := Dataset @ Transpose @ Join[ Transpose[dataset], AssociationThread[columnNamesDataset[AssociationThread[columnNames, columns]columns]] ]; The new column can now be added as follows:
addColumnToDataset[ds, newdata, "col3"] edit Interestingly, I just realized that you can also add columns by using Part-assignment:
data[[All, "col3"]] = newdata; Dataset[data] However, it seems this only works on lists-of-associations like data and not on Datasets like ds. You can get around that by switching back and forth between the two with Normal and Dataset. And if you don't like in-place modification, you can always use Block or Module to create a temporary variable on which you do the in-place modification.