Qu

nrow

Builtin index · Collections & strings

result = nrow(df)

Input: df · Output: result

What it is

df is a Table.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = nrow(df)
df Tablenot documented yet
result number
Returns a number: the row count. df.nrows is property-style sugar for this — see below.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

t = read_csv(path, headers = true)
print("rows: {nrow(t)}")
print(head(t, 2))

from agent-guide

df = table(x=[1,2,3], y=[10,20,-5])
print(df)
print("nrow = {nrow(df)}")
print("ncol = {ncol(df)}")
print("df.nrows = {df.nrows}")
print("rows(df) = {rows(df)}")
output
x   y
-  --
1  10
2  20
3  -5
nrow = 3
ncol = 2
df.nrows = 3
rows(df) = 3

from tour

df = DataFrame(x=[1, 2, 3, 4, 5], y=[10, 20, 30, 40, 50], label="sample")
print(nrow(df))            # 5

print(ncol(df))             # 3

tall = filter(df, df.x > 2)
xy = select(tall, "x", "y")
print(xy)
print(describe(df))
output
5
3
x   y
-  --
3  30
4  40
5  50
stat          x          y
-----  --------  ---------
count         5          5
mean          3         30
std    1.581139  15.811388
min           1         10
25%           2         20
    ... 3 more lines

from collections-strings

measurements = table(
    x = [-1.5, 0.5, 2.0, -0.25, 3.75],
    sensor = ["a", "b", "a", "c", "b"]
)
write_csv(measurements, "measurements.csv")

df = read_csv("measurements.csv")
print(nrow(df))
print(describe(df))
write_csv(filter(df, df.x > 0), "positive_only.csv")
print(read_all_text("positive_only.csv"))
output
5
stat         x
-----  -------
count        5
mean       0.9
std    2.03562
min       -1.5
25%      -0.25
50%        0.5
75%          2
max       3.75
x,sensor
0.5,b
2,a
    ... 1 more lines

from file-io

How it works

nrow/ncol answer for anything shape answers for, and they answer it by ASKING shape -- nrow(x) is shape(x)[0] by construction, so the two cannot drift. They used to take a table and nothing else, which made nrow(m) on a matrix -- the obvious spelling -- an error naming tables. The duplication was already flagged in shape_of's own comment, which notes that rows/cols "must return exactly the same values the dedicated nrow/ncol match arms compute": two places computing one answer, kept in step by hand. shape_of returns None for a value with no shape rather than the old silent (0, 0), so these refuse instead of reporting zero rows for a function.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.