withColumnNamesChanged method
A new data frame with the column names changed.
Example:
print(iris.withHead(3));
print(iris.withHead(3).withColumnNamesChanged({
"sepal_width": "sw",
"petal_width": "pw",
}));
.--.------------.-----------.------------.-----------.--------.
|id|sepal_length|sepal_width|petal_length|petal_width|species |
:--+------------+-----------+------------+-----------+--------:
|1 |5.1 |3.5 |1.4 |0.2 |setosa |
|2 |4.9 |3.0 |1.4 |0.2 |setosa |
|3 |4.7 |3.2 |1.3 |0.2 |setosa |
'--'------------'-----------'------------'-----------'--------'
.--.------------.---.------------.---.--------.
|id|sepal_length|sw |petal_length|pw |species |
:--+------------+---+------------+---+--------:
|1 |5.1 |3.5|1.4 |0.2|setosa |
|2 |4.9 |3.0|1.4 |0.2|setosa |
|3 |4.7 |3.2|1.3 |0.2|setosa |
'--'------------'---'------------'---'--------'
Implementation
DataFrame withColumnNamesChanged(Map<String, String> changes) {
final numericColumns = <String, NumericColumn>{},
categoricColumns = <String, CategoricColumn>{};
for (final MapEntry(:key, :value) in this.numericColumns.entries) {
numericColumns[changes.containsKey(key) ? changes[key]! : key] =
NumericColumn(value.values);
}
for (final MapEntry(:key, :value) in this.categoricColumns.entries) {
categoricColumns[changes.containsKey(key) ? changes[key]! : key] =
CategoricColumn(value.values);
}
return DataFrame(
numericColumns: numericColumns,
categoricColumns: categoricColumns,
);
}