Files
df-research/dataframe/docs/StardustDocs/topics/update.md
2026-02-08 11:20:43 -10:00

2.5 KiB
Vendored

Returns DataFrame with changed values in some cells. Column types can not be changed.

update { columns }
    [.where { rowCondition } ]
    [.at(rowIndices) ] 
     .with { rowExpression } | .notNull { rowExpression } | .perCol { colExpression } | .perRowCol { rowColExpression } | .withNull() | .withZero() | .asFrame { frameExpression } 

rowCondition: DataRow.(OldValue) -> Boolean
rowExpression: DataRow.(OldValue) -> NewValue
colExpression: DataColumn.(DataColumn) -> NewValue
rowColExpression: (DataRow, DataColumn) -> NewValue
frameExpression: DataFrame.(DataFrame) -> DataFrame

Related operations:

See column selectors for how to select the columns for this operation and row expressions for how to specify the new values.

df.update { age }.with { it * 2 }
df.update { colsAtAnyDepth().colsOf<String>() }.with { it.uppercase() }
df.update { weight }.at(1..4).notNull { it / 2 }
df.update { name.lastName and age }.at(1, 3, 4).withNull()

Update with constant value:

df.update { city }.where { name.firstName == "Alice" }.with { "Paris" }

Update with value depending on row:

df.update { city }.with { name.firstName + " from " + it }

Update with value depending on column:

df.update { colsOf<Number?>() }.perCol { mean(skipNaN = true) }

Update with value depending on row and column:

df.update { colsOf<String?>() }.perRowCol { row, col -> col.name() + ": " + row.index() }

Update ColumnGroup as DataFrame:

df.update { name }.asFrame { select { lastName } }