Skip to content
Open in Anthropic

DataFrame

The main data structure for tabular data.

Creating

DataFrame.fromColumns(data)

Create from column objects:

typescript
const df = DataFrame.fromColumns({
  name: ["Alice", "Bob"],
  age: [25, 30],
});

DataFrame.empty(schema)

Create an empty DataFrame with a schema.

Properties

PropertyTypeDescription
shape[number, number][rows, columns]
heightnumberRow count
widthnumberColumn count

Methods

Selection

MethodDescription
col(name)Get a Series by column name
columns()Get column names
select(cols)Select specific columns
drop(cols)Remove columns

Filtering

MethodDescription
filter(fn)Keep rows where fn returns true
where(col, op, val)Filter by column condition
head(n)First n rows
tail(n)Last n rows

Sorting

MethodDescription
sort(col, asc?)Sort by column

Grouping

MethodDescription
groupby(cols)Group by column(s)

GroupBy aggregations: agg({ col: op }), sum(cols), mean(cols), count(). Supported ops: sum, mean, min, max, count, first, last.

Transformation

MethodDescription
rename(mapping)Rename columns
assign(name, values)Add new column
apply(fn)Transform each row
copy()Deep copy

Missing Values

MethodDescription
dropna()Remove rows with NaN
fillna(value)Replace NaN values
isna()Boolean DataFrame of NaN positions

Combining

MethodDescription
concat(dfs)Vertical concatenation
merge(other, opts)SQL-like join
unique()Remove duplicate rows

Display

MethodDescription
print()Print ASCII table
toString()Get as string
describe()Summary statistics
info()Column info

Released under the MIT License.