withHead method
A new data frame with only the first n
rows.
Example:
print(petals.withHead(3));
.--.------------.-----------.--------.
|id|petal_length|petal_width|species |
:--+------------+-----------+--------:
|1 |1.4 |0.2 |setosa |
|2 |1.4 |0.2 |setosa |
|3 |1.3 |0.2 |setosa |
'--'------------'-----------'--------'
Implementation
DataFrame withHead([int n = 10]) {
final numberOfRows = this.rowNumber;
return withRowsAtIndices(
[for (var i = 0; i < math.min(numberOfRows, n); i++) i]);
}