df-script 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -235
- package/dist/api.d.ts +41 -36
- package/dist/columnExpressions/ColumnExpr.d.ts +5 -8
- package/dist/columnExpressions/functions/all.d.ts +13 -13
- package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
- package/dist/columnExpressions/functions/duration.d.ts +16 -21
- package/dist/columnExpressions/functions/element.d.ts +10 -10
- package/dist/columnExpressions/functions/exclude.d.ts +14 -14
- package/dist/columnExpressions/functions/implode.d.ts +7 -7
- package/dist/columnExpressions/functions/lit.d.ts +9 -9
- package/dist/columnExpressions/functions/seqRange.d.ts +69 -0
- package/dist/columnExpressions/functions/struct.d.ts +6 -6
- package/dist/columnExpressions/functions/when.d.ts +25 -28
- package/dist/columnExpressions/index.d.ts +3 -7
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +550 -221
- package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +701 -327
- package/dist/columnExpressions/mixins/ArrayExpr.d.ts +508 -212
- package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +398 -201
- package/dist/columnExpressions/mixins/LogicalExpr.d.ts +59 -29
- package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +23 -9
- package/dist/columnExpressions/mixins/StandardExpr.d.ts +3234 -0
- package/dist/columnExpressions/mixins/StringExpr.d.ts +1163 -524
- package/dist/columnExpressions/mixins/StructExpr.d.ts +67 -25
- package/dist/columnExpressions/mixins/TemporalExpr.d.ts +518 -212
- package/dist/columnExpressions/mixins/WindowExpr.d.ts +270 -102
- package/dist/columnExpressions/typeInference.d.ts +3 -3
- package/dist/columnExpressions/types.d.ts +5 -0
- package/dist/columnExpressions/utils.d.ts +7 -0
- package/dist/constants.d.ts +11 -2
- package/dist/dataframe/dataframe.d.ts +755 -592
- package/dist/dataframe/grouped/grouped.d.ts +24 -6
- package/dist/dataframe/grouped.d.ts +70 -0
- package/dist/dataframe/index.d.ts +1 -1
- package/dist/dataframe/lazy.d.ts +37 -0
- package/dist/dataframe/types.d.ts +46 -22
- package/dist/dataframe/utils.d.ts +10 -4
- package/dist/datatypes/index.d.ts +11 -4
- package/dist/expressions.js +1 -0
- package/dist/expressions.mjs +1 -0
- package/dist/functions/concat.d.ts +68 -16
- package/dist/functions/index.d.ts +2 -2
- package/dist/functions/readCsv.d.ts +35 -0
- package/dist/functions/readJson.d.ts +33 -0
- package/dist/index.js +5 -6
- package/dist/index.mjs +5 -6
- package/dist/types.d.ts +42 -9
- package/dist/utils/array.d.ts +17 -14
- package/dist/utils/csv.d.ts +4 -1
- package/dist/utils/date.d.ts +3 -19
- package/dist/utils/duration.d.ts +7 -5
- package/dist/utils/json.d.ts +5 -3
- package/dist/utils/object.d.ts +0 -18
- package/dist/utils/string.d.ts +5 -0
- package/dist/utils.js +4 -0
- package/dist/utils.mjs +4 -0
- package/package.json +29 -8
- package/dist/assets/index-DBhGK6Tp.css +0 -1
- package/dist/assets/index-DEJEV_tU.js +0 -195
- package/dist/index.html +0 -17
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GroupedData } from "./grouped
|
|
1
|
+
import { GroupedData } from "./grouped";
|
|
2
2
|
import type { IExpr, ColumnData, ColumnDict, DataFrameColumns, ConcatOptions, ConcatItem, HorizontalConcatOptions, RowRecord, DataFrameSchema, RegisteredDataType, ExplodeOptions, IntoExpr, FillNullOptions } from "../types";
|
|
3
|
-
import type { LimitOptions, SortOptions, PivotOptions, JoinOptions,
|
|
3
|
+
import type { LimitOptions, SortOptions, PivotOptions, JoinOptions, JoinAsofOptions, JoinWhereOptions, GroupByDynamicOptions, UnpivotOptions, TransposeOptions, WriteJSONOptions, WriteCSVOptions } from "./types";
|
|
4
4
|
/**
|
|
5
5
|
* Two-dimensional columnar tabular data structure supporting expression execution and reshaping.
|
|
6
6
|
*/
|
|
@@ -29,20 +29,47 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
29
29
|
* └─────┴─────┘
|
|
30
30
|
*/
|
|
31
31
|
constructor(data: T[] | ColumnDict, schema?: DataFrameSchema, height?: number);
|
|
32
|
-
private _inferSchema;
|
|
33
32
|
private _applySchema;
|
|
33
|
+
private _inferSchema;
|
|
34
|
+
private _normalizeArgs;
|
|
34
35
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
36
|
+
* Creates a deep copy of the current DataFrame instance, duplicating all underlying column data arrays and schema metadata.
|
|
37
|
+
* Modifying columns or values in the cloned DataFrame will not mutate the original.
|
|
38
|
+
* @returns {DataFrame<T>}
|
|
37
39
|
* @example
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
41
|
+
* >>> df
|
|
42
|
+
* shape: (2, 2)
|
|
43
|
+
* ┌───┬───┐
|
|
44
|
+
* │ a │ b │
|
|
45
|
+
* ├───┼───┤
|
|
46
|
+
* │ 1 │ x │
|
|
47
|
+
* │ 2 │ y │
|
|
48
|
+
* └───┴───┘
|
|
49
|
+
* >>> const cloned = df.clone()
|
|
50
|
+
* >>> cloned
|
|
51
|
+
* shape: (2, 2)
|
|
41
52
|
* ┌───┬───┐
|
|
42
53
|
* │ a │ b │
|
|
43
54
|
* ├───┼───┤
|
|
44
|
-
* │ 1 │
|
|
55
|
+
* │ 1 │ x │
|
|
56
|
+
* │ 2 │ y │
|
|
45
57
|
* └───┴───┘
|
|
58
|
+
*/
|
|
59
|
+
clone(): DataFrame<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Gets array of column names in the DataFrame.
|
|
62
|
+
* @returns Array of column name strings.
|
|
63
|
+
* @example
|
|
64
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
65
|
+
* >>> df
|
|
66
|
+
* shape: (2, 2)
|
|
67
|
+
* ┌───┬───┐
|
|
68
|
+
* │ a │ b │
|
|
69
|
+
* ├───┼───┤
|
|
70
|
+
* │ 1 │ x │
|
|
71
|
+
* │ 2 │ y │
|
|
72
|
+
* └───┴───┘
|
|
46
73
|
* >>> df.columns
|
|
47
74
|
* ["a", "b"]
|
|
48
75
|
*/
|
|
@@ -58,49 +85,94 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
58
85
|
*
|
|
59
86
|
* @example
|
|
60
87
|
* // 1. Vertical Concatenation (default):
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
88
|
+
* >>> const df1 = $df.data({ a: [1, 2] })
|
|
89
|
+
* >>> const df2 = $df.data({ b: [10, 20] })
|
|
90
|
+
* >>> df1
|
|
91
|
+
* shape: (2, 1)
|
|
92
|
+
* ┌───┐
|
|
93
|
+
* │ a │
|
|
94
|
+
* ├───┤
|
|
95
|
+
* │ 1 │
|
|
96
|
+
* │ 2 │
|
|
97
|
+
* └───┘
|
|
98
|
+
* >>> df2
|
|
99
|
+
* shape: (2, 1)
|
|
100
|
+
* ┌────┐
|
|
101
|
+
* │ b │
|
|
102
|
+
* ├────┤
|
|
103
|
+
* │ 10 │
|
|
104
|
+
* │ 20 │
|
|
105
|
+
* └────┘
|
|
70
106
|
* >>> df1.concat(df2, { how: "vertical" })
|
|
71
|
-
* shape: (
|
|
72
|
-
*
|
|
73
|
-
* │ a
|
|
74
|
-
*
|
|
75
|
-
* │ 1
|
|
76
|
-
* │ 2
|
|
77
|
-
*
|
|
107
|
+
* shape: (4, 1)
|
|
108
|
+
* ┌──────┐
|
|
109
|
+
* │ a │
|
|
110
|
+
* ├──────┤
|
|
111
|
+
* │ 1 │
|
|
112
|
+
* │ 2 │
|
|
113
|
+
* │ null │
|
|
114
|
+
* │ null │
|
|
115
|
+
* └──────┘
|
|
78
116
|
*
|
|
79
117
|
* @example
|
|
80
118
|
* // 2. Horizontal Concatenation:
|
|
81
|
-
|
|
82
|
-
|
|
119
|
+
* >>> const df1 = $df.data({ a: [1, 2] })
|
|
120
|
+
* >>> const df2 = $df.data({ b: [10, 20] })
|
|
121
|
+
* >>> df1
|
|
122
|
+
* shape: (2, 1)
|
|
123
|
+
* ┌───┐
|
|
124
|
+
* │ a │
|
|
125
|
+
* ├───┤
|
|
126
|
+
* │ 1 │
|
|
127
|
+
* │ 2 │
|
|
128
|
+
* └───┘
|
|
129
|
+
* >>> df2
|
|
130
|
+
* shape: (2, 1)
|
|
131
|
+
* ┌────┐
|
|
132
|
+
* │ b │
|
|
133
|
+
* ├────┤
|
|
134
|
+
* │ 10 │
|
|
135
|
+
* │ 20 │
|
|
136
|
+
* └────┘
|
|
83
137
|
* >>> df1.concat(df2, { how: "horizontal" })
|
|
84
|
-
* shape: (
|
|
85
|
-
*
|
|
86
|
-
* │ a │ b
|
|
87
|
-
*
|
|
88
|
-
* │ 1 │
|
|
89
|
-
*
|
|
138
|
+
* shape: (2, 2)
|
|
139
|
+
* ┌───┬────┐
|
|
140
|
+
* │ a │ b │
|
|
141
|
+
* ├───┼────┤
|
|
142
|
+
* │ 1 │ 10 │
|
|
143
|
+
* │ 2 │ 20 │
|
|
144
|
+
* └───┴────┘
|
|
90
145
|
*
|
|
91
146
|
* @example
|
|
92
147
|
* // 3. Diagonal Concatenation (mismatched columns):
|
|
93
|
-
|
|
94
|
-
|
|
148
|
+
* >>> const df1 = $df.data({ a: [1, 2] })
|
|
149
|
+
* >>> const df2 = $df.data({ b: [10, 20] })
|
|
150
|
+
* >>> df1
|
|
151
|
+
* shape: (2, 1)
|
|
152
|
+
* ┌───┐
|
|
153
|
+
* │ a │
|
|
154
|
+
* ├───┤
|
|
155
|
+
* │ 1 │
|
|
156
|
+
* │ 2 │
|
|
157
|
+
* └───┘
|
|
158
|
+
* >>> df2
|
|
159
|
+
* shape: (2, 1)
|
|
160
|
+
* ┌────┐
|
|
161
|
+
* │ b │
|
|
162
|
+
* ├────┤
|
|
163
|
+
* │ 10 │
|
|
164
|
+
* │ 20 │
|
|
165
|
+
* └────┘
|
|
95
166
|
* >>> df1.concat(df2, { how: "diagonal" })
|
|
96
|
-
* shape: (
|
|
167
|
+
* shape: (4, 2)
|
|
97
168
|
* ┌──────┬──────┐
|
|
98
169
|
* │ a │ b │
|
|
99
170
|
* ├──────┼──────┤
|
|
100
171
|
* │ 1 │ null │
|
|
101
|
-
* │ null │
|
|
172
|
+
* │ 2 │ null │
|
|
173
|
+
* │ null │ 10 │
|
|
174
|
+
* │ null │ 20 │
|
|
102
175
|
* └──────┴──────┘
|
|
103
|
-
*
|
|
104
176
|
*/
|
|
105
177
|
concat<U extends RowRecord = any>(items: ConcatItem | ConcatItem[], options?: ConcatOptions): DataFrame<U>;
|
|
106
178
|
/**
|
|
@@ -108,39 +180,41 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
108
180
|
* @param {(K | K[])[]} args Column names or arrays of column names to remove.
|
|
109
181
|
* @returns {DataFrame}
|
|
110
182
|
* @example
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
183
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
184
|
+
* >>> df
|
|
185
|
+
* shape: (2, 2)
|
|
186
|
+
* ┌───┬───┐
|
|
187
|
+
* │ a │ b │
|
|
188
|
+
* ├───┼───┤
|
|
189
|
+
* │ 1 │ x │
|
|
190
|
+
* │ 2 │ y │
|
|
191
|
+
* └───┴───┘
|
|
119
192
|
* >>> df.drop("b")
|
|
120
|
-
* shape: (
|
|
193
|
+
* shape: (2, 1)
|
|
121
194
|
* ┌───┐
|
|
122
195
|
* │ a │
|
|
123
196
|
* ├───┤
|
|
124
197
|
* │ 1 │
|
|
198
|
+
* │ 2 │
|
|
125
199
|
* └───┘
|
|
126
200
|
*/
|
|
127
201
|
drop<K extends keyof T>(...args: (K | K[])[]): DataFrame<Omit<T, K>>;
|
|
128
202
|
/**
|
|
129
|
-
* Drops rows
|
|
203
|
+
* Drops rows with null or undefined values.
|
|
130
204
|
* @param {string | string[]} [subset] Column name or array of column names to check for nulls.
|
|
131
205
|
* @returns {DataFrame}
|
|
132
206
|
* @example
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
* >>> df.
|
|
207
|
+
* >>> const df = $df.data({ a: [1, null, 3], b: [null, 2, null] })
|
|
208
|
+
* >>> df
|
|
209
|
+
* shape: (3, 2)
|
|
210
|
+
* ┌──────┬──────┐
|
|
211
|
+
* │ a │ b │
|
|
212
|
+
* ├──────┼──────┤
|
|
213
|
+
* │ 1 │ null │
|
|
214
|
+
* │ null │ 2 │
|
|
215
|
+
* │ 3 │ null │
|
|
216
|
+
* └──────┴──────┘
|
|
217
|
+
* >>> df.dropNulls()
|
|
144
218
|
* shape: (2, 1)
|
|
145
219
|
* ┌───┐
|
|
146
220
|
* │ a │
|
|
@@ -149,19 +223,20 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
149
223
|
* │ 3 │
|
|
150
224
|
* └───┘
|
|
151
225
|
*/
|
|
152
|
-
|
|
226
|
+
dropNulls(subset?: string | string[]): DataFrame<T>;
|
|
153
227
|
/**
|
|
154
228
|
* Gets array of registered column DataTypes matching current schema order.
|
|
155
229
|
* @returns Array of RegisteredDataType definitions.
|
|
156
230
|
* @example
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
231
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
232
|
+
* >>> df
|
|
233
|
+
* shape: (2, 2)
|
|
234
|
+
* ┌───┬───┐
|
|
235
|
+
* │ a │ b │
|
|
236
|
+
* ├───┼───┤
|
|
237
|
+
* │ 1 │ x │
|
|
238
|
+
* │ 2 │ y │
|
|
239
|
+
* └───┴───┘
|
|
165
240
|
* >>> df.dtypes
|
|
166
241
|
* [Float64, Utf8]
|
|
167
242
|
*/
|
|
@@ -170,18 +245,19 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
170
245
|
* Explodes an array column into multiple rows, replicating non-target row attributes.
|
|
171
246
|
* @param {IntoExpr | IntoExpr[]} columns Target column expression or array column name to explode.
|
|
172
247
|
* @param {ExplodeOptions} [options] Configuration options for empty array and null handling.
|
|
173
|
-
* @param {boolean} [options.
|
|
174
|
-
* @param {boolean} [options.
|
|
248
|
+
* @param {boolean} [options.emptyAsNull] When `true`, converts empty arrays to `null` rows.
|
|
249
|
+
* @param {boolean} [options.keepNulls] When `true`, retains `null` array values during explosion.
|
|
175
250
|
* @returns {DataFrame}
|
|
176
251
|
* @example
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
252
|
+
* >>> const df = $df.data({ a: [[1, 2, 3], [4, 5]] })
|
|
253
|
+
* >>> df
|
|
254
|
+
* shape: (2, 1)
|
|
255
|
+
* ┌───────────┐
|
|
256
|
+
* │ a │
|
|
257
|
+
* ├───────────┤
|
|
258
|
+
* │ [1, 2, 3] │
|
|
259
|
+
* │ [4, 5] │
|
|
260
|
+
* └───────────┘
|
|
185
261
|
* >>> df.explode("values")
|
|
186
262
|
* shape: (2, 2)
|
|
187
263
|
* ┌───────┬────────┐
|
|
@@ -200,17 +276,17 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
200
276
|
* @param {number} [options.limit] Maximum consecutive nulls to fill when using propagation strategies.
|
|
201
277
|
* @returns {DataFrame}
|
|
202
278
|
* @example
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
* >>> df.
|
|
279
|
+
* >>> const df = $df.data({ a: [1, null, 3], b: [null, 2, null] })
|
|
280
|
+
* >>> df
|
|
281
|
+
* shape: (3, 2)
|
|
282
|
+
* ┌──────┬──────┐
|
|
283
|
+
* │ a │ b │
|
|
284
|
+
* ├──────┼──────┤
|
|
285
|
+
* │ 1 │ null │
|
|
286
|
+
* │ null │ 2 │
|
|
287
|
+
* │ 3 │ null │
|
|
288
|
+
* └──────┴──────┘
|
|
289
|
+
* >>> df.fillNull({ value: 0 })
|
|
214
290
|
* shape: (3, 1)
|
|
215
291
|
* ┌───┐
|
|
216
292
|
* │ a │
|
|
@@ -220,22 +296,22 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
220
296
|
* │ 3 │
|
|
221
297
|
* └───┘
|
|
222
298
|
*/
|
|
223
|
-
|
|
299
|
+
fillNull(options?: FillNullOptions): DataFrame<T>;
|
|
224
300
|
/**
|
|
225
301
|
* Filters rows matching boolean column expressions or predicate callbacks.
|
|
226
302
|
* @param {(IExpr | ((row: T) => any))[]} exprs Expressions or predicate functions evaluated per row.
|
|
227
303
|
* @returns {DataFrame}
|
|
228
304
|
* @example
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
305
|
+
* >>> const df = $df.data({ a: [1, 2, 3], b: [10, 20, 30] })
|
|
306
|
+
* >>> df
|
|
307
|
+
* shape: (3, 2)
|
|
308
|
+
* ┌───┬────┐
|
|
309
|
+
* │ a │ b │
|
|
310
|
+
* ├───┼────┤
|
|
311
|
+
* │ 1 │ 10 │
|
|
312
|
+
* │ 2 │ 20 │
|
|
313
|
+
* │ 3 │ 30 │
|
|
314
|
+
* └───┴────┘
|
|
239
315
|
* >>> df.filter($df.col("a").gt(1))
|
|
240
316
|
* shape: (2, 1)
|
|
241
317
|
* ┌───┐
|
|
@@ -251,17 +327,17 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
251
327
|
* @param {K | K[]} keys Column name or array of key column names.
|
|
252
328
|
* @returns {GroupedData}
|
|
253
329
|
* @example
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
* >>> df.
|
|
330
|
+
* >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
|
|
331
|
+
* >>> df
|
|
332
|
+
* shape: (3, 2)
|
|
333
|
+
* ┌───────┬─────┐
|
|
334
|
+
* │ group │ val │
|
|
335
|
+
* ├───────┼─────┤
|
|
336
|
+
* │ A │ 10 │
|
|
337
|
+
* │ A │ 20 │
|
|
338
|
+
* │ B │ 30 │
|
|
339
|
+
* └───────┴─────┘
|
|
340
|
+
* >>> df.groupBy("group").agg($df.col("val").sum().alias("sum"))
|
|
265
341
|
* shape: (2, 2)
|
|
266
342
|
* ┌─────┬─────┐
|
|
267
343
|
* │ cat │ sum │
|
|
@@ -270,23 +346,53 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
270
346
|
* │ B │ 30 │
|
|
271
347
|
* └─────┴─────┘
|
|
272
348
|
*/
|
|
273
|
-
|
|
349
|
+
groupBy<K extends keyof T>(keys: K | K[]): GroupedData<T, K>;
|
|
350
|
+
/**
|
|
351
|
+
* Groups dynamically based on a time or integer index column over sliding / stepping windows.
|
|
352
|
+
*
|
|
353
|
+
* @param indexColumn The time/integer column or column expression to group on.
|
|
354
|
+
* @param options Dynamic grouping configuration options (`every`, `period`, `offset`, `truncate`, `includeBoundaries`, `closed`, `label`, `by`, `startBy`, `checkSorted`).
|
|
355
|
+
* @returns GroupedData
|
|
356
|
+
* @example
|
|
357
|
+
* >>> const df = $df.data([
|
|
358
|
+
* ... { time: new Date("2024-01-01T00:00:00Z"), val: 10 },
|
|
359
|
+
* ... { time: new Date("2024-01-01T12:00:00Z"), val: 20 },
|
|
360
|
+
* ... { time: new Date("2024-01-02T00:00:00Z"), val: 30 }
|
|
361
|
+
* ... ])
|
|
362
|
+
* >>> df
|
|
363
|
+
* shape: (3, 2)
|
|
364
|
+
* ┌──────────────────────────┬─────┐
|
|
365
|
+
* │ time │ val │
|
|
366
|
+
* ├──────────────────────────┼─────┤
|
|
367
|
+
* │ 2024-01-01T00:00:00.000Z │ 10 │
|
|
368
|
+
* │ 2024-01-01T12:00:00.000Z │ 20 │
|
|
369
|
+
* │ 2024-01-02T00:00:00.000Z │ 30 │
|
|
370
|
+
* └──────────────────────────┴─────┘
|
|
371
|
+
* >>> df.groupByDynamic("time", { every: "1d", period: "1d" }).agg($df.col("val").sum().alias("daily_sum"))
|
|
372
|
+
* shape: (2, 2)
|
|
373
|
+
* ┌──────────────────────────┬───────────┐
|
|
374
|
+
* │ time │ daily_sum │
|
|
375
|
+
* ├──────────────────────────┼───────────┤
|
|
376
|
+
* │ 2024-01-01T00:00:00.000Z │ 30 │
|
|
377
|
+
* │ 2024-01-02T00:00:00.000Z │ 30 │
|
|
378
|
+
* └──────────────────────────┴───────────┘
|
|
379
|
+
*/
|
|
380
|
+
groupByDynamic<K extends keyof T & string>(indexColumn: K | IntoExpr, options: GroupByDynamicOptions<T>): GroupedData<T, K>;
|
|
274
381
|
/**
|
|
275
382
|
* Returns the first N rows as a new DataFrame.
|
|
276
383
|
* @param n Number of leading rows to slice (default 10).
|
|
277
384
|
* @returns DataFrame
|
|
278
385
|
* @example
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
* └───┘
|
|
386
|
+
* >>> const df = $df.data({ a: [1, 2, 3] })
|
|
387
|
+
* >>> df
|
|
388
|
+
* shape: (3, 1)
|
|
389
|
+
* ┌───┐
|
|
390
|
+
* │ a │
|
|
391
|
+
* ├───┤
|
|
392
|
+
* │ 1 │
|
|
393
|
+
* │ 2 │
|
|
394
|
+
* │ 3 │
|
|
395
|
+
* └───┘
|
|
290
396
|
* >>> df.head(2)
|
|
291
397
|
* shape: (2, 1)
|
|
292
398
|
* ┌───┐
|
|
@@ -297,49 +403,19 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
297
403
|
* └───┘
|
|
298
404
|
*/
|
|
299
405
|
head(n?: number): DataFrame<T>;
|
|
300
|
-
/**
|
|
301
|
-
* Creates a deep copy of the current DataFrame instance, duplicating all underlying column data arrays and schema metadata.
|
|
302
|
-
* Modifying columns or values in the cloned DataFrame will not mutate the original.
|
|
303
|
-
* @returns {DataFrame<T>}
|
|
304
|
-
* @example
|
|
305
|
-
* >>> // Example 1: Basic cloning and independence
|
|
306
|
-
* >>> const df1 = $df.data({ a: [10, 20], b: ["x", "y"] })
|
|
307
|
-
* >>> const copy1 = df1.clone()
|
|
308
|
-
* >>> copy1
|
|
309
|
-
* shape: (2, 2)
|
|
310
|
-
* ┌────┬───┐
|
|
311
|
-
* │ a │ b │
|
|
312
|
-
* ├────┼───┤
|
|
313
|
-
* │ 10 │ x │
|
|
314
|
-
* │ 20 │ y │
|
|
315
|
-
* └────┴───┘
|
|
316
|
-
*
|
|
317
|
-
* >>> // Example 2: Verifying mutation isolation
|
|
318
|
-
* >>> copy1._columns.a[0] = 999
|
|
319
|
-
* >>> df1.to_dicts()[0].a
|
|
320
|
-
* 10
|
|
321
|
-
*
|
|
322
|
-
* >>> // Example 3: Cloning empty DataFrames
|
|
323
|
-
* >>> const emptyDf = $df.data({ x: [], y: [] })
|
|
324
|
-
* >>> const emptyCopy = emptyDf.clone()
|
|
325
|
-
* >>> emptyCopy.height
|
|
326
|
-
* 0
|
|
327
|
-
*/
|
|
328
|
-
clone(): DataFrame<T>;
|
|
329
406
|
/**
|
|
330
407
|
* Gets height (total row count) of the DataFrame.
|
|
331
408
|
* @returns Number of rows.
|
|
332
409
|
* @example
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
* └────┘
|
|
410
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
411
|
+
* >>> df
|
|
412
|
+
* shape: (2, 2)
|
|
413
|
+
* ┌───┬───┐
|
|
414
|
+
* │ a │ b │
|
|
415
|
+
* ├───┼───┤
|
|
416
|
+
* │ 1 │ x │
|
|
417
|
+
* │ 2 │ y │
|
|
418
|
+
* └───┴───┘
|
|
343
419
|
* >>> df.height
|
|
344
420
|
* 3
|
|
345
421
|
*/
|
|
@@ -351,16 +427,24 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
351
427
|
* @param {boolean} [options.strict] When `true` (default), throws an error if row counts mismatch. Set `false` to allow null padding.
|
|
352
428
|
* @returns {DataFrame}
|
|
353
429
|
* @example
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
430
|
+
* >>> const df1 = $df.data({ a: [1, 2] })
|
|
431
|
+
* >>> const df2 = $df.data({ b: [10, 20] })
|
|
432
|
+
* >>> df1
|
|
433
|
+
* shape: (2, 1)
|
|
434
|
+
* ┌───┐
|
|
435
|
+
* │ a │
|
|
436
|
+
* ├───┤
|
|
437
|
+
* │ 1 │
|
|
438
|
+
* │ 2 │
|
|
439
|
+
* └───┘
|
|
440
|
+
* >>> df2
|
|
441
|
+
* shape: (2, 1)
|
|
442
|
+
* ┌────┐
|
|
443
|
+
* │ b │
|
|
444
|
+
* ├────┤
|
|
445
|
+
* │ 10 │
|
|
446
|
+
* │ 20 │
|
|
447
|
+
* └────┘
|
|
364
448
|
* >>> df1.hstack(df2)
|
|
365
449
|
* shape: (2, 2)
|
|
366
450
|
* ┌───┬────┐
|
|
@@ -378,23 +462,25 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
378
462
|
* @param {IntoExpr} expr Value expression or column definition.
|
|
379
463
|
* @returns {DataFrame}
|
|
380
464
|
* @example
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
465
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
466
|
+
* >>> df
|
|
467
|
+
* shape: (2, 2)
|
|
468
|
+
* ┌───┬───┐
|
|
469
|
+
* │ a │ b │
|
|
470
|
+
* ├───┼───┤
|
|
471
|
+
* │ 1 │ x │
|
|
472
|
+
* │ 2 │ y │
|
|
473
|
+
* └───┴───┘
|
|
474
|
+
* >>> df.insertColumn(1, "c", [10, 20])
|
|
475
|
+
* shape: (2, 3)
|
|
476
|
+
* ┌───┬────┬───┐
|
|
477
|
+
* │ a │ c │ b │
|
|
478
|
+
* ├───┼────┼───┤
|
|
479
|
+
* │ 1 │ 10 │ x │
|
|
480
|
+
* │ 2 │ 20 │ y │
|
|
481
|
+
* └───┴────┴───┘
|
|
396
482
|
*/
|
|
397
|
-
|
|
483
|
+
insertColumn(index: number, name: string, expr: IntoExpr): DataFrame<any>;
|
|
398
484
|
/**
|
|
399
485
|
* Retrieves a single scalar cell value by row and column position or name.
|
|
400
486
|
* @param {number} [row] Row index position.
|
|
@@ -403,14 +489,15 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
403
489
|
* @throws {DataFrameError} If shape is not (1, 1) when called without arguments.
|
|
404
490
|
* @throws {ShapeError} If row or column index is out of bounds.
|
|
405
491
|
* @example
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
492
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
493
|
+
* >>> df
|
|
494
|
+
* shape: (2, 2)
|
|
495
|
+
* ┌───┬───┐
|
|
496
|
+
* │ a │ b │
|
|
497
|
+
* ├───┼───┤
|
|
498
|
+
* │ 1 │ x │
|
|
499
|
+
* │ 2 │ y │
|
|
500
|
+
* └───┴───┘
|
|
414
501
|
* >>> df.item(0, "val")
|
|
415
502
|
* 42
|
|
416
503
|
*/
|
|
@@ -419,50 +506,48 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
419
506
|
* Yields a generator iterating over raw column arrays.
|
|
420
507
|
* @returns Generator of ColumnData arrays.
|
|
421
508
|
* @example
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
* >>>
|
|
432
|
-
* Float64Array([1, 2])
|
|
433
|
-
* Float64Array([3, 4])
|
|
509
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
510
|
+
* >>> df
|
|
511
|
+
* shape: (2, 2)
|
|
512
|
+
* ┌───┬───┐
|
|
513
|
+
* │ a │ b │
|
|
514
|
+
* ├───┼───┤
|
|
515
|
+
* │ 1 │ x │
|
|
516
|
+
* │ 2 │ y │
|
|
517
|
+
* └───┴───┘
|
|
518
|
+
* >>> Array.from(df.iterColumns())
|
|
519
|
+
* [ Float64Array([1, 2]), ["x", "y"] ]
|
|
434
520
|
*/
|
|
435
|
-
|
|
521
|
+
iterColumns(): Generator<ColumnData>;
|
|
436
522
|
/**
|
|
437
523
|
* Yields a generator iterating over rows as tuples or named objects.
|
|
438
524
|
* @param [config] Iteration format configuration.
|
|
439
525
|
* @param [config.named] When `true`, yields row objects with column keys (`{ col: val }`). When `false` (default), yields positional arrays (`[val1, val2]`).
|
|
440
526
|
* @returns Generator of rows.
|
|
441
527
|
* @example
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
* >>>
|
|
452
|
-
* { a: 1, b: "x" }
|
|
453
|
-
* { a: 2, b: "y" }
|
|
528
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
529
|
+
* >>> df
|
|
530
|
+
* shape: (2, 2)
|
|
531
|
+
* ┌───┬───┐
|
|
532
|
+
* │ a │ b │
|
|
533
|
+
* ├───┼───┤
|
|
534
|
+
* │ 1 │ x │
|
|
535
|
+
* │ 2 │ y │
|
|
536
|
+
* └───┴───┘
|
|
537
|
+
* >>> Array.from(df.iterRows({ named: true }))
|
|
538
|
+
* [ { a: 1, b: "x" }, { a: 2, b: "y" } ]
|
|
454
539
|
*/
|
|
455
|
-
|
|
540
|
+
iterRows({ named }?: {
|
|
456
541
|
named?: boolean;
|
|
457
542
|
}): Generator<any[] | Record<string, any>>;
|
|
458
543
|
/**
|
|
459
544
|
* Joins two DataFrames on key columns using a specified join strategy.
|
|
460
|
-
* @param {
|
|
461
|
-
* @param {
|
|
462
|
-
* @param {string | string[]} [
|
|
463
|
-
* @param {string | string[]} [
|
|
464
|
-
* @param {string | string[]} [
|
|
465
|
-
* @param {JoinType} [
|
|
545
|
+
* @param {DataFrame} other Right DataFrame to join with.
|
|
546
|
+
* @param {JoinOptions} [options={}] Join configuration object.
|
|
547
|
+
* @param {string | string[]} [options.on] Join key column name or array of key column names that exist in both DataFrames.
|
|
548
|
+
* @param {string | string[]} [options.leftOn] Join key column(s) in the left DataFrame when key names differ.
|
|
549
|
+
* @param {string | string[]} [options.rightOn] Join key column(s) in the right DataFrame when key names differ.
|
|
550
|
+
* @param {JoinType} [options.how] Join strategy. Default `"inner"`.
|
|
466
551
|
* - `"inner"` — Only rows with matching keys in both DataFrames.
|
|
467
552
|
* - `"left"` — All left rows; unmatched right values are `null`.
|
|
468
553
|
* - `"right"` — All right rows; unmatched left values are `null`.
|
|
@@ -470,12 +555,12 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
470
555
|
* - `"semi"` — Left rows that have a match in the right DataFrame (only left columns retained).
|
|
471
556
|
* - `"anti"` — Left rows that have **no** match in the right DataFrame (only left columns retained).
|
|
472
557
|
* - `"cross"` — Cartesian product pairing every left row with every right row (keyless).
|
|
473
|
-
* @param {[string, string]} [
|
|
558
|
+
* @param {[string, string]} [options.suffixes] Suffix tuple `[leftSuffix, rightSuffix]` appended to overlapping
|
|
474
559
|
* non-key column names (default `["", "_right"]`). Ignored for `"semi"` and `"anti"` joins.
|
|
475
|
-
* @param {boolean} [
|
|
560
|
+
* @param {boolean} [options.joinNulls] If `true`, null key values are treated as equal and will match each other
|
|
476
561
|
* across DataFrames. Default `false` (SQL-standard: `NULL != NULL`).
|
|
477
|
-
* @param {boolean} [
|
|
478
|
-
* @param {JoinMaintainOrder | boolean} [
|
|
562
|
+
* @param {boolean} [options.coalesce] Coalescing behavior for join key columns. Default `true`. If `true`, coalesces join key values into left key columns and drops right key columns. If `false`, keeps join key columns separate.
|
|
563
|
+
* @param {JoinMaintainOrder | boolean} [options.maintainOrder] Row order preservation strategy. Default `"none"`.
|
|
479
564
|
* - `"none"` (or `false`) — No specific ordering is desired.
|
|
480
565
|
* - `"left"` (or `true`) — Preserves the order of the left DataFrame.
|
|
481
566
|
* - `"right"` — Preserves the order of the right DataFrame.
|
|
@@ -483,17 +568,25 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
483
568
|
* - `"right_left"` — Preserves the order of the right DataFrame first, then the left.
|
|
484
569
|
* @returns {DataFrame}
|
|
485
570
|
* @example
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
571
|
+
* >>> const df1 = $df.data({ id: [1, 2], val: ["a", "b"] })
|
|
572
|
+
* >>> const df2 = $df.data({ id: [1, 2], num: [100, 200] })
|
|
573
|
+
* >>> df1
|
|
574
|
+
* shape: (2, 2)
|
|
575
|
+
* ┌────┬─────┐
|
|
576
|
+
* │ id │ val │
|
|
577
|
+
* ├────┼─────┤
|
|
578
|
+
* │ 1 │ a │
|
|
579
|
+
* │ 2 │ b │
|
|
580
|
+
* └────┴─────┘
|
|
581
|
+
* >>> df2
|
|
582
|
+
* shape: (2, 2)
|
|
583
|
+
* ┌────┬─────┐
|
|
584
|
+
* │ id │ num │
|
|
585
|
+
* ├────┼─────┤
|
|
586
|
+
* │ 1 │ 100 │
|
|
587
|
+
* │ 2 │ 200 │
|
|
588
|
+
* └────┴─────┘
|
|
589
|
+
* >>> df1.join(df2, { on: "id" })
|
|
497
590
|
* shape: (2, 3)
|
|
498
591
|
* ┌────┬─────┬─────┐
|
|
499
592
|
* │ id │ val │ num │
|
|
@@ -502,7 +595,7 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
502
595
|
* │ 2 │ b │ 200 │
|
|
503
596
|
* └────┴─────┴─────┘
|
|
504
597
|
*/
|
|
505
|
-
join<U extends RowRecord = any, R extends RowRecord = any>(
|
|
598
|
+
join<U extends RowRecord = any, R extends RowRecord = any>(other: DataFrame<U>, options?: JoinOptions<T, U>): DataFrame<R>;
|
|
506
599
|
/**
|
|
507
600
|
* Performs an asof (as-of) join for inexact matching on ordered numeric or temporal key columns.
|
|
508
601
|
*
|
|
@@ -510,71 +603,123 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
510
603
|
* DataFrame according to the selected `strategy` ("backward", "forward", or "nearest") and optional `tolerance`.
|
|
511
604
|
* Both DataFrames must be sorted in ascending order on their respective `on` / `leftOn` / `rightOn` join keys.
|
|
512
605
|
*
|
|
513
|
-
* @param {
|
|
514
|
-
* @param {
|
|
606
|
+
* @param {DataFrame} other The right DataFrame to join with.
|
|
607
|
+
* @param {JoinAsofOptions} options Asof join configuration options.
|
|
515
608
|
* @param {string} [options.on] Column name to join on (must exist in both DataFrames and be sorted ascending).
|
|
516
609
|
* @param {string} [options.leftOn] Left DataFrame join key column name.
|
|
517
610
|
* @param {string} [options.rightOn] Right DataFrame join key column name.
|
|
518
611
|
* @param {string | string[]} [options.by] Optional exact-match group column(s) present in both DataFrames.
|
|
519
612
|
* @param {string | string[]} [options.leftBy] Group column(s) for exact key matching in left DataFrame.
|
|
520
613
|
* @param {string | string[]} [options.rightBy] Group column(s) for exact key matching in right DataFrame.
|
|
521
|
-
* @param {
|
|
614
|
+
* @param {JoinAsofStrategy} [options.strategy] Match search strategy. Default `"backward"`.
|
|
522
615
|
* - `"backward"` — Matches the latest right row where `rightKey <= leftKey`.
|
|
523
616
|
* - `"forward"` — Matches the earliest right row where `rightKey >= leftKey`.
|
|
524
617
|
* - `"nearest"` — Matches the right row with the absolute nearest key value to `leftKey`.
|
|
525
618
|
* @param {number | string} [options.tolerance] Maximum allowed distance between left key and right key.
|
|
526
|
-
* @param {boolean} [options.
|
|
619
|
+
* @param {boolean} [options.allowExactMatches] Whether exact key matches are permitted. Default `true`.
|
|
527
620
|
* @param {[string, string]} [options.suffixes] Column name suffixes `[leftSuffix, rightSuffix]` to resolve name collisions. Default `["", "_right"]`.
|
|
528
621
|
* @param {boolean} [options.coalesce] Coalescing behavior for join key columns. Default `true`.
|
|
529
|
-
* @param {boolean} [options.
|
|
622
|
+
* @param {boolean} [options.checkSorted] Whether to verify that join keys are sorted ascending prior to matching. Default `true`.
|
|
530
623
|
* @returns A new DataFrame containing the joined results.
|
|
531
|
-
*
|
|
532
|
-
* @namespace df
|
|
533
|
-
* @category DataFrame
|
|
534
|
-
* @syntax
|
|
535
|
-
* df.join_asof({
|
|
536
|
-
* other,
|
|
537
|
-
* on,
|
|
538
|
-
* leftOn,
|
|
539
|
-
* rightOn,
|
|
540
|
-
* by,
|
|
541
|
-
* leftBy,
|
|
542
|
-
* rightBy,
|
|
543
|
-
* strategy,
|
|
544
|
-
* tolerance,
|
|
545
|
-
* allow_exact_matches,
|
|
546
|
-
* suffixes,
|
|
547
|
-
* coalesce,
|
|
548
|
-
* check_sorted
|
|
549
|
-
* })
|
|
550
624
|
* @example
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
625
|
+
* >>> const trades = $df.data([
|
|
626
|
+
* ... { time: 1000, ticker: "AAPL", price: 150.0 },
|
|
627
|
+
* ... { time: 1005, ticker: "AAPL", price: 150.5 },
|
|
628
|
+
* ... { time: 1015, ticker: "AAPL", price: 151.0 }
|
|
629
|
+
* ... ])
|
|
630
|
+
* >>> const quotes = $df.data([
|
|
631
|
+
* ... { time: 998, ticker: "AAPL", bid: 149.9 },
|
|
632
|
+
* ... { time: 1004, ticker: "AAPL", bid: 150.4 },
|
|
633
|
+
* ... { time: 1010, ticker: "AAPL", bid: 150.8 }
|
|
634
|
+
* ... ])
|
|
635
|
+
* >>> trades
|
|
636
|
+
* shape: (3, 3)
|
|
637
|
+
* ┌──────┬────────┬───────┐
|
|
638
|
+
* │ time │ ticker │ price │
|
|
639
|
+
* ├──────┼────────┼───────┤
|
|
640
|
+
* │ 1000 │ AAPL │ 150.0 │
|
|
641
|
+
* │ 1005 │ AAPL │ 150.5 │
|
|
642
|
+
* │ 1015 │ AAPL │ 151.0 │
|
|
643
|
+
* └──────┴────────┴───────┘
|
|
644
|
+
* >>> quotes
|
|
645
|
+
* shape: (3, 3)
|
|
646
|
+
* ┌──────┬────────┬───────┐
|
|
647
|
+
* │ time │ ticker │ bid │
|
|
648
|
+
* ├──────┼────────┼───────┤
|
|
649
|
+
* │ 998 │ AAPL │ 149.9 │
|
|
650
|
+
* │ 1004 │ AAPL │ 150.4 │
|
|
651
|
+
* │ 1010 │ AAPL │ 150.8 │
|
|
652
|
+
* └──────┴────────┴───────┘
|
|
653
|
+
* >>> trades.joinAsof(quotes, { on: "time", by: "ticker" })
|
|
568
654
|
* shape: (3, 4)
|
|
569
|
-
*
|
|
570
|
-
* │ time │ ticker │ price │ bid
|
|
571
|
-
*
|
|
572
|
-
* │ 1000 │ AAPL │ 150.0 │ 149.9│
|
|
573
|
-
* │ 1005 │ AAPL │ 150.5 │ 150.4│
|
|
574
|
-
* │ 1015 │ AAPL │ 151.0 │ 150.8│
|
|
575
|
-
*
|
|
655
|
+
* ┌──────┬────────┬───────┬───────┐
|
|
656
|
+
* │ time │ ticker │ price │ bid │
|
|
657
|
+
* ├──────┼────────┼───────┼───────┤
|
|
658
|
+
* │ 1000 │ AAPL │ 150.0 │ 149.9 │
|
|
659
|
+
* │ 1005 │ AAPL │ 150.5 │ 150.4 │
|
|
660
|
+
* │ 1015 │ AAPL │ 151.0 │ 150.8 │
|
|
661
|
+
* └──────┴────────┴───────┴───────┘
|
|
662
|
+
*/
|
|
663
|
+
joinAsof<U extends RowRecord = any, R extends RowRecord = any>(other: DataFrame<U>, options: JoinAsofOptions<T, U>): DataFrame<R>;
|
|
664
|
+
/**
|
|
665
|
+
* Joins two DataFrames based on arbitrary expression predicates (non-equi joins).
|
|
666
|
+
*
|
|
667
|
+
* Evaluates one or more boolean expressions across combined rows from both DataFrames.
|
|
668
|
+
* When column names collide between the two DataFrames, columns are suffixed according to
|
|
669
|
+
* `options.suffixes` (default `["", "_right"]`).
|
|
670
|
+
*
|
|
671
|
+
* @param {DataFrame} other The right DataFrame to join with.
|
|
672
|
+
* @param {...(IntoExpr | IntoExpr[] | JoinWhereOptions)} args Predicate expression(s), arrays of expressions,
|
|
673
|
+
* and an optional configuration options object (`{ how, suffixes }`).
|
|
674
|
+
* @returns {DataFrame} A new DataFrame containing the joined results.
|
|
675
|
+
* @example
|
|
676
|
+
* >>> const east = $df.data([
|
|
677
|
+
* ... { id: 100, dur: 120, rev: 12, cores: 2 },
|
|
678
|
+
* ... { id: 101, dur: 140, rev: 14, cores: 8 },
|
|
679
|
+
* ... { id: 102, dur: 160, rev: 16, cores: 4 }
|
|
680
|
+
* ... ])
|
|
681
|
+
* >>> const west = $df.data([
|
|
682
|
+
* ... { t_id: 404, time: 90, cost: 9, cores: 4 },
|
|
683
|
+
* ... { t_id: 498, time: 130, cost: 13, cores: 2 },
|
|
684
|
+
* ... { t_id: 676, time: 150, cost: 15, cores: 1 },
|
|
685
|
+
* ... { t_id: 742, time: 170, cost: 16, cores: 4 }
|
|
686
|
+
* ... ])
|
|
687
|
+
* >>> east
|
|
688
|
+
* shape: (3, 4)
|
|
689
|
+
* ┌─────┬─────┬─────┬───────┐
|
|
690
|
+
* │ id │ dur │ rev │ cores │
|
|
691
|
+
* ├─────┼─────┼─────┼───────┤
|
|
692
|
+
* │ 100 │ 120 │ 12 │ 2 │
|
|
693
|
+
* │ 101 │ 140 │ 14 │ 8 │
|
|
694
|
+
* │ 102 │ 160 │ 16 │ 4 │
|
|
695
|
+
* └─────┴─────┴─────┴───────┘
|
|
696
|
+
* >>> west
|
|
697
|
+
* shape: (4, 4)
|
|
698
|
+
* ┌──────┬──────┬──────┬───────┐
|
|
699
|
+
* │ t_id │ time │ cost │ cores │
|
|
700
|
+
* ├──────┼──────┼──────┼───────┤
|
|
701
|
+
* │ 404 │ 90 │ 9 │ 4 │
|
|
702
|
+
* │ 498 │ 130 │ 13 │ 2 │
|
|
703
|
+
* │ 676 │ 150 │ 15 │ 1 │
|
|
704
|
+
* │ 742 │ 170 │ 16 │ 4 │
|
|
705
|
+
* └──────┴──────┴──────┴───────┘
|
|
706
|
+
* >>> east.joinWhere(
|
|
707
|
+
* ... west,
|
|
708
|
+
* ... $df.col("dur").lt($df.col("time")),
|
|
709
|
+
* ... $df.col("rev").lt($df.col("cost"))
|
|
710
|
+
* ... )
|
|
711
|
+
* shape: (5, 8)
|
|
712
|
+
* ┌─────┬─────┬─────┬───────┬──────┬──────┬──────┬─────────────┐
|
|
713
|
+
* │ id │ dur │ rev │ cores │ t_id │ time │ cost │ cores_right │
|
|
714
|
+
* ├─────┼─────┼─────┼───────┼──────┼──────┼──────┼─────────────┤
|
|
715
|
+
* │ 100 │ 120 │ 12 │ 2 │ 498 │ 130 │ 13 │ 2 │
|
|
716
|
+
* │ 100 │ 120 │ 12 │ 2 │ 676 │ 150 │ 15 │ 1 │
|
|
717
|
+
* │ 100 │ 120 │ 12 │ 2 │ 742 │ 170 │ 16 │ 4 │
|
|
718
|
+
* │ 101 │ 140 │ 14 │ 8 │ 676 │ 150 │ 15 │ 1 │
|
|
719
|
+
* │ 101 │ 140 │ 14 │ 8 │ 742 │ 170 │ 16 │ 4 │
|
|
720
|
+
* └─────┴─────┴─────┴───────┴──────┴──────┴──────┴─────────────┘
|
|
576
721
|
*/
|
|
577
|
-
|
|
722
|
+
joinWhere<U extends RowRecord = any, R extends RowRecord = any>(other: DataFrame<U>, ...args: (IntoExpr | IntoExpr[] | JoinWhereOptions)[]): DataFrame<R>;
|
|
578
723
|
/**
|
|
579
724
|
* Limits the output to N rows starting from offset.
|
|
580
725
|
* @param {number} n Maximum number of rows to take.
|
|
@@ -583,17 +728,16 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
583
728
|
* @param {LimitPosition} [options.from] Slice direction starting point (`"start"` or `"end"`). Default `"start"`.
|
|
584
729
|
* @returns {DataFrame}
|
|
585
730
|
* @example
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
* └────┘
|
|
731
|
+
* >>> const df = $df.data({ a: [1, 2, 3] })
|
|
732
|
+
* >>> df
|
|
733
|
+
* shape: (3, 1)
|
|
734
|
+
* ┌───┐
|
|
735
|
+
* │ a │
|
|
736
|
+
* ├───┤
|
|
737
|
+
* │ 1 │
|
|
738
|
+
* │ 2 │
|
|
739
|
+
* │ 3 │
|
|
740
|
+
* └───┘
|
|
597
741
|
* >>> df.limit(2, { offset: 1 })
|
|
598
742
|
* shape: (2, 1)
|
|
599
743
|
* ┌────┐
|
|
@@ -613,21 +757,17 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
613
757
|
* @param {AggFn | string} [config.agg] Aggregation function to apply when multiple values exist for a cell.
|
|
614
758
|
* @returns DataFrame
|
|
615
759
|
* @example
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
* │ 2020 │ Feb │ 150 │
|
|
628
|
-
* │ 2021 │ Jan │ 120 │
|
|
629
|
-
* │ 2021 │ Feb │ 180 │
|
|
630
|
-
* └──────┴───────┴─────────┘
|
|
760
|
+
* >>> const df = $df.data({ year: [2020, 2020, 2021, 2021], month: ["Jan", "Feb", "Jan", "Feb"], revenue: [100, 150, 120, 180] })
|
|
761
|
+
* >>> df
|
|
762
|
+
* shape: (4, 3)
|
|
763
|
+
* ┌──────┬───────┬─────────┐
|
|
764
|
+
* │ year │ month │ revenue │
|
|
765
|
+
* ├──────┼───────┼─────────┤
|
|
766
|
+
* │ 2020 │ Jan │ 100 │
|
|
767
|
+
* │ 2020 │ Feb │ 150 │
|
|
768
|
+
* │ 2021 │ Jan │ 120 │
|
|
769
|
+
* │ 2021 │ Feb │ 180 │
|
|
770
|
+
* └──────┴───────┴─────────┘
|
|
631
771
|
* >>> df.pivot({ index: "year", columns: "month", values: "revenue" })
|
|
632
772
|
* shape: (2, 3)
|
|
633
773
|
* ┌──────┬─────┬─────┐
|
|
@@ -643,60 +783,61 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
643
783
|
* @param {Partial<Record<keyof T, string>>} [mapping] Dictionary mapping old column names to new names.
|
|
644
784
|
* @returns {DataFrame}
|
|
645
785
|
* @example
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
786
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
787
|
+
* >>> df
|
|
788
|
+
* shape: (2, 2)
|
|
789
|
+
* ┌───┬───┐
|
|
790
|
+
* │ a │ b │
|
|
791
|
+
* ├───┼───┤
|
|
792
|
+
* │ 1 │ x │
|
|
793
|
+
* │ 2 │ y │
|
|
794
|
+
* └───┴───┘
|
|
795
|
+
* >>> df.rename({ a: "id", b: "label" })
|
|
796
|
+
* shape: (2, 2)
|
|
797
|
+
* ┌────┬───────┐
|
|
798
|
+
* │ id │ label │
|
|
799
|
+
* ├────┼───────┤
|
|
800
|
+
* │ 1 │ x │
|
|
801
|
+
* │ 2 │ y │
|
|
802
|
+
* └────┴───────┘
|
|
661
803
|
*/
|
|
662
804
|
rename(mapping?: Partial<Record<keyof T, string>>): DataFrame<any>;
|
|
663
805
|
/**
|
|
664
806
|
* Reverses the row ordering of the DataFrame.
|
|
665
807
|
* @returns DataFrame
|
|
666
808
|
* @example
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
* └───┘
|
|
809
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
810
|
+
* >>> df
|
|
811
|
+
* shape: (2, 2)
|
|
812
|
+
* ┌───┬───┐
|
|
813
|
+
* │ a │ b │
|
|
814
|
+
* ├───┼───┤
|
|
815
|
+
* │ 1 │ x │
|
|
816
|
+
* │ 2 │ y │
|
|
817
|
+
* └───┴───┘
|
|
677
818
|
* >>> df.reverse()
|
|
678
|
-
* shape: (
|
|
679
|
-
*
|
|
680
|
-
* │ a │
|
|
681
|
-
*
|
|
682
|
-
* │
|
|
683
|
-
* │
|
|
684
|
-
*
|
|
685
|
-
* └───┘
|
|
819
|
+
* shape: (2, 2)
|
|
820
|
+
* ┌───┬───┐
|
|
821
|
+
* │ a │ b │
|
|
822
|
+
* ├───┼───┤
|
|
823
|
+
* │ 2 │ y │
|
|
824
|
+
* │ 1 │ x │
|
|
825
|
+
* └───┴───┘
|
|
686
826
|
*/
|
|
687
827
|
reverse(): DataFrame<T>;
|
|
688
828
|
/**
|
|
689
829
|
* Gets current DataFrameSchema dictionary mapping column names to DataType.
|
|
690
830
|
* @returns DataFrameSchema mapping.
|
|
691
831
|
* @example
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
832
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
833
|
+
* >>> df
|
|
834
|
+
* shape: (2, 2)
|
|
835
|
+
* ┌───┬───┐
|
|
836
|
+
* │ a │ b │
|
|
837
|
+
* ├───┼───┤
|
|
838
|
+
* │ 1 │ x │
|
|
839
|
+
* │ 2 │ y │
|
|
840
|
+
* └───┴───┘
|
|
700
841
|
* >>> df.schema
|
|
701
842
|
* { a: Float64, b: Utf8 }
|
|
702
843
|
*/
|
|
@@ -706,15 +847,15 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
706
847
|
* @param {(string | IExpr | Record<string, any> | (string | IExpr | Record<string, any>)[])[]} args Column names, column expressions, or object maps to evaluate.
|
|
707
848
|
* @returns {DataFrame}
|
|
708
849
|
* @example
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
850
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
851
|
+
* >>> df
|
|
852
|
+
* shape: (2, 2)
|
|
853
|
+
* ┌───┬───┐
|
|
854
|
+
* │ a │ b │
|
|
855
|
+
* ├───┼───┤
|
|
856
|
+
* │ 1 │ x │
|
|
857
|
+
* │ 2 │ y │
|
|
858
|
+
* └───┴───┘
|
|
718
859
|
* >>> df.select("a", $df.col("b").add(100).alias("b_plus"))
|
|
719
860
|
* shape: (2, 2)
|
|
720
861
|
* ┌───┬────────┐
|
|
@@ -729,15 +870,15 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
729
870
|
* Gets DataFrame dimensions as [height, width] tuple.
|
|
730
871
|
* @returns Tuple [height, width].
|
|
731
872
|
* @example
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
873
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
874
|
+
* >>> df
|
|
875
|
+
* shape: (2, 2)
|
|
876
|
+
* ┌───┬───┐
|
|
877
|
+
* │ a │ b │
|
|
878
|
+
* ├───┼───┤
|
|
879
|
+
* │ 1 │ x │
|
|
880
|
+
* │ 2 │ y │
|
|
881
|
+
* └───┴───┘
|
|
741
882
|
* >>> df.shape
|
|
742
883
|
* [2, 2]
|
|
743
884
|
*/
|
|
@@ -748,17 +889,16 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
748
889
|
* @param {number} [end] Optional ending row index (exclusive).
|
|
749
890
|
* @returns {DataFrame}
|
|
750
891
|
* @example
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
* └────┘
|
|
892
|
+
* >>> const df = $df.data({ a: [1, 2, 3] })
|
|
893
|
+
* >>> df
|
|
894
|
+
* shape: (3, 1)
|
|
895
|
+
* ┌───┐
|
|
896
|
+
* │ a │
|
|
897
|
+
* ├───┤
|
|
898
|
+
* │ 1 │
|
|
899
|
+
* │ 2 │
|
|
900
|
+
* │ 3 │
|
|
901
|
+
* └───┘
|
|
762
902
|
* >>> df.slice(1, 3)
|
|
763
903
|
* shape: (2, 1)
|
|
764
904
|
* ┌────┐
|
|
@@ -778,25 +918,25 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
778
918
|
* @param {Partial<Record<keyof T, (a: any, b: any) => number>>} [config.custom] Optional dictionary mapping column names to custom comparator functions.
|
|
779
919
|
* @returns {DataFrame}
|
|
780
920
|
* @example
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
* >>> df.sort({ by: "
|
|
792
|
-
* shape: (3,
|
|
793
|
-
*
|
|
794
|
-
* │
|
|
795
|
-
*
|
|
796
|
-
* │
|
|
797
|
-
* │ 2
|
|
798
|
-
* │
|
|
799
|
-
*
|
|
921
|
+
* >>> const df = $df.data({ a: [1, 2, 3], b: [10, 20, 30] })
|
|
922
|
+
* >>> df
|
|
923
|
+
* shape: (3, 2)
|
|
924
|
+
* ┌───┬────┐
|
|
925
|
+
* │ a │ b │
|
|
926
|
+
* ├───┼────┤
|
|
927
|
+
* │ 1 │ 10 │
|
|
928
|
+
* │ 2 │ 20 │
|
|
929
|
+
* │ 3 │ 30 │
|
|
930
|
+
* └───┴────┘
|
|
931
|
+
* >>> df.sort({ by: "a", descending: true })
|
|
932
|
+
* shape: (3, 2)
|
|
933
|
+
* ┌───┬────┐
|
|
934
|
+
* │ a │ b │
|
|
935
|
+
* ├───┼────┤
|
|
936
|
+
* │ 3 │ 30 │
|
|
937
|
+
* │ 2 │ 20 │
|
|
938
|
+
* │ 1 │ 10 │
|
|
939
|
+
* └───┴────┘
|
|
800
940
|
*/
|
|
801
941
|
sort(config?: SortOptions<T>): DataFrame<T>;
|
|
802
942
|
/**
|
|
@@ -804,17 +944,16 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
804
944
|
* @param n Number of trailing rows to take (default 10).
|
|
805
945
|
* @returns DataFrame
|
|
806
946
|
* @example
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
* └───┘
|
|
947
|
+
* >>> const df = $df.data({ a: [1, 2, 3] })
|
|
948
|
+
* >>> df
|
|
949
|
+
* shape: (3, 1)
|
|
950
|
+
* ┌───┐
|
|
951
|
+
* │ a │
|
|
952
|
+
* ├───┤
|
|
953
|
+
* │ 1 │
|
|
954
|
+
* │ 2 │
|
|
955
|
+
* │ 3 │
|
|
956
|
+
* └───┘
|
|
818
957
|
* >>> df.tail(2)
|
|
819
958
|
* shape: (2, 1)
|
|
820
959
|
* ┌───┐
|
|
@@ -825,75 +964,78 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
825
964
|
* └───┘
|
|
826
965
|
*/
|
|
827
966
|
tail(n?: number): DataFrame<T>;
|
|
967
|
+
/**
|
|
968
|
+
* Evaluates a column expression or retrieves column values as a raw JavaScript array.
|
|
969
|
+
* @param {K | IExpr} nameOrExpr Target column name or column expression.
|
|
970
|
+
* @returns {any[]} Array of column scalar values.
|
|
971
|
+
* @example
|
|
972
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
973
|
+
* >>> df
|
|
974
|
+
* shape: (2, 2)
|
|
975
|
+
* ┌───┬───┐
|
|
976
|
+
* │ a │ b │
|
|
977
|
+
* ├───┼───┤
|
|
978
|
+
* │ 1 │ x │
|
|
979
|
+
* │ 2 │ y │
|
|
980
|
+
* └───┴───┘
|
|
981
|
+
* >>> df.toArray("a")
|
|
982
|
+
* [10, 20]
|
|
983
|
+
*/
|
|
984
|
+
toArray<K extends keyof T>(nameOrExpr: K | IExpr): any[];
|
|
828
985
|
/**
|
|
829
986
|
* Converts columns into a JavaScript dictionary mapping column keys to raw arrays.
|
|
830
987
|
* @returns Column dictionary map.
|
|
831
988
|
* @example
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
* >>> df.
|
|
989
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
990
|
+
* >>> df
|
|
991
|
+
* shape: (2, 2)
|
|
992
|
+
* ┌───┬───┐
|
|
993
|
+
* │ a │ b │
|
|
994
|
+
* ├───┼───┤
|
|
995
|
+
* │ 1 │ x │
|
|
996
|
+
* │ 2 │ y │
|
|
997
|
+
* └───┴───┘
|
|
998
|
+
* >>> df.toDict()
|
|
842
999
|
* { a: Float64Array([1, 2]), b: ["x", "y"] }
|
|
843
1000
|
*/
|
|
844
|
-
|
|
1001
|
+
toDict(): DataFrameColumns<T>;
|
|
845
1002
|
/**
|
|
846
1003
|
* Converts rows into an array of JavaScript objects.
|
|
847
1004
|
* @returns Array of row record objects.
|
|
848
1005
|
* @example
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1006
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
1007
|
+
* >>> df
|
|
1008
|
+
* shape: (2, 2)
|
|
1009
|
+
* ┌───┬───┐
|
|
1010
|
+
* │ a │ b │
|
|
1011
|
+
* ├───┼───┤
|
|
1012
|
+
* │ 1 │ x │
|
|
1013
|
+
* │ 2 │ y │
|
|
1014
|
+
* └───┴───┘
|
|
1015
|
+
* >>> df.toDicts()
|
|
858
1016
|
* [{ a: 1, b: "x" }]
|
|
859
1017
|
*/
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* Evaluates a column expression or retrieves column values as a raw JavaScript array.
|
|
863
|
-
* @param {K | IExpr} nameOrExpr Target column name or column expression.
|
|
864
|
-
* @returns {any[]} Array of column scalar values.
|
|
865
|
-
* @example
|
|
866
|
-
* >>> const df = $df.data({ a: [10, 20] })
|
|
867
|
-
* >>> df
|
|
868
|
-
* shape: (2, 1)
|
|
869
|
-
* ┌────┐
|
|
870
|
-
* │ a │
|
|
871
|
-
* ├────┤
|
|
872
|
-
* │ 10 │
|
|
873
|
-
* │ 20 │
|
|
874
|
-
* └────┘
|
|
875
|
-
* >>> df.to_array("a")
|
|
876
|
-
* [10, 20]
|
|
877
|
-
*/
|
|
878
|
-
to_array<K extends keyof T>(nameOrExpr: K | IExpr): any[];
|
|
1018
|
+
toDicts(): T[];
|
|
879
1019
|
/**
|
|
880
1020
|
* Transposes rows into columns and columns into rows.
|
|
881
1021
|
* @param {TransposeOptions} [options] Transpose layout options.
|
|
882
|
-
* @param {boolean} [options.
|
|
883
|
-
* @param {string} [options.
|
|
884
|
-
* @param {string | Iterable<string>} [options.
|
|
1022
|
+
* @param {boolean} [options.includeHeader] When `true`, includes original column names as a new header column (default `false`).
|
|
1023
|
+
* @param {string} [options.headerName] Name of the header column when `includeHeader` is `true` (default `"column"`).
|
|
1024
|
+
* @param {string | Iterable<string>} [options.columnNames] Column name or iterable of strings to use as transposed column headers.
|
|
885
1025
|
* @returns {DataFrame}
|
|
886
1026
|
* @example
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1027
|
+
* >>> const df = $df.data({ year: [2020, 2020, 2021, 2021], month: ["Jan", "Feb", "Jan", "Feb"], revenue: [100, 150, 120, 180] })
|
|
1028
|
+
* >>> df
|
|
1029
|
+
* shape: (4, 3)
|
|
1030
|
+
* ┌──────┬───────┬─────────┐
|
|
1031
|
+
* │ year │ month │ revenue │
|
|
1032
|
+
* ├──────┼───────┼─────────┤
|
|
1033
|
+
* │ 2020 │ Jan │ 100 │
|
|
1034
|
+
* │ 2020 │ Feb │ 150 │
|
|
1035
|
+
* │ 2021 │ Jan │ 120 │
|
|
1036
|
+
* │ 2021 │ Feb │ 180 │
|
|
1037
|
+
* └──────┴───────┴─────────┘
|
|
1038
|
+
* >>> df.transpose({ includeHeader: true, headerName: "metric" })
|
|
897
1039
|
* shape: (2, 3)
|
|
898
1040
|
* ┌────────┬──────────┬──────────┐
|
|
899
1041
|
* │ metric │ column_0 │ column_1 │
|
|
@@ -902,22 +1044,21 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
902
1044
|
* │ q2 │ 120 │ 600 │
|
|
903
1045
|
* └────────┴──────────┴──────────┘
|
|
904
1046
|
*/
|
|
905
|
-
transpose({
|
|
1047
|
+
transpose({ includeHeader: includeHeader, headerName: headerName, columnNames: colNamesOpt }?: TransposeOptions): DataFrame<any>;
|
|
906
1048
|
/**
|
|
907
1049
|
* Filters distinct unique rows matching target key columns.
|
|
908
1050
|
* @param {K | K[]} [columns] Target column or array of column names to evaluate uniqueness.
|
|
909
1051
|
* @returns {DataFrame}
|
|
910
1052
|
* @example
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
* └───┴───┘
|
|
1053
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
1054
|
+
* >>> df
|
|
1055
|
+
* shape: (2, 2)
|
|
1056
|
+
* ┌───┬───┐
|
|
1057
|
+
* │ a │ b │
|
|
1058
|
+
* ├───┼───┤
|
|
1059
|
+
* │ 1 │ x │
|
|
1060
|
+
* │ 2 │ y │
|
|
1061
|
+
* └───┴───┘
|
|
921
1062
|
* >>> df.unique()
|
|
922
1063
|
* shape: (2, 2)
|
|
923
1064
|
* ┌───┬───┐
|
|
@@ -937,22 +1078,27 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
937
1078
|
* @param {string} [config.valueName] Name for the new value column holding cell values (default `"value"`).
|
|
938
1079
|
* @returns {DataFrame}
|
|
939
1080
|
* @example
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
* │
|
|
955
|
-
*
|
|
1081
|
+
* >>> const df = $df.data({ year: [2020, 2020, 2021, 2021], month: ["Jan", "Feb", "Jan", "Feb"], revenue: [100, 150, 120, 180] })
|
|
1082
|
+
* >>> df
|
|
1083
|
+
* shape: (4, 3)
|
|
1084
|
+
* ┌──────┬───────┬─────────┐
|
|
1085
|
+
* │ year │ month │ revenue │
|
|
1086
|
+
* ├──────┼───────┼─────────┤
|
|
1087
|
+
* │ 2020 │ Jan │ 100 │
|
|
1088
|
+
* │ 2020 │ Feb │ 150 │
|
|
1089
|
+
* │ 2021 │ Jan │ 120 │
|
|
1090
|
+
* │ 2021 │ Feb │ 180 │
|
|
1091
|
+
* └──────┴───────┴─────────┘
|
|
1092
|
+
* >>> df.unpivot({ idVars: "metric", valueVars: ["q1", "q2"], varName: "quarter", valueName: "val" })
|
|
1093
|
+
* shape: (4, 3)
|
|
1094
|
+
* ┌────────┬─────────┬─────┐
|
|
1095
|
+
* │ metric │ quarter │ val │
|
|
1096
|
+
* ├────────┼─────────┼─────┤
|
|
1097
|
+
* │ sales │ q1 │ 100 │
|
|
1098
|
+
* │ sales │ q2 │ 120 │
|
|
1099
|
+
* │ clicks │ q1 │ 500 │
|
|
1100
|
+
* │ clicks │ q2 │ 600 │
|
|
1101
|
+
* └────────┴─────────┴─────┘
|
|
956
1102
|
*/
|
|
957
1103
|
unpivot<U extends RowRecord = any>(config: UnpivotOptions<T>): DataFrame<U>;
|
|
958
1104
|
/**
|
|
@@ -960,93 +1106,132 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
960
1106
|
* @param {ConcatItem | ConcatItem[]} other Single DataFrame or array of DataFrames to append vertically.
|
|
961
1107
|
* @returns {DataFrame}
|
|
962
1108
|
* @example
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1109
|
+
* >>> const df1 = $df.data({ a: [1, 2] })
|
|
1110
|
+
* >>> const df2 = $df.data({ b: [10, 20] })
|
|
1111
|
+
* >>> df1
|
|
1112
|
+
* shape: (2, 1)
|
|
1113
|
+
* ┌───┐
|
|
1114
|
+
* │ a │
|
|
1115
|
+
* ├───┤
|
|
1116
|
+
* │ 1 │
|
|
1117
|
+
* │ 2 │
|
|
1118
|
+
* └───┘
|
|
1119
|
+
* >>> df2
|
|
1120
|
+
* shape: (2, 1)
|
|
1121
|
+
* ┌────┐
|
|
1122
|
+
* │ b │
|
|
1123
|
+
* ├────┤
|
|
1124
|
+
* │ 10 │
|
|
1125
|
+
* │ 20 │
|
|
1126
|
+
* └────┘
|
|
972
1127
|
* >>> df1.vstack(df2)
|
|
973
|
-
* shape: (
|
|
974
|
-
*
|
|
975
|
-
* │ a
|
|
976
|
-
*
|
|
977
|
-
* │ 1
|
|
978
|
-
* │ 2
|
|
979
|
-
*
|
|
1128
|
+
* shape: (4, 1)
|
|
1129
|
+
* ┌──────┐
|
|
1130
|
+
* │ a │
|
|
1131
|
+
* ├──────┤
|
|
1132
|
+
* │ 1 │
|
|
1133
|
+
* │ 2 │
|
|
1134
|
+
* │ null │
|
|
1135
|
+
* │ null │
|
|
1136
|
+
* └──────┘
|
|
980
1137
|
*/
|
|
981
1138
|
vstack<U extends RowRecord = any>(other: ConcatItem | ConcatItem[]): DataFrame<U>;
|
|
982
1139
|
/**
|
|
983
1140
|
* Gets width (total column count) of the DataFrame.
|
|
984
1141
|
* @returns Number of columns.
|
|
985
1142
|
* @example
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1143
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
1144
|
+
* >>> df
|
|
1145
|
+
* shape: (2, 2)
|
|
1146
|
+
* ┌───┬───┐
|
|
1147
|
+
* │ a │ b │
|
|
1148
|
+
* ├───┼───┤
|
|
1149
|
+
* │ 1 │ x │
|
|
1150
|
+
* │ 2 │ y │
|
|
1151
|
+
* └───┴───┘
|
|
994
1152
|
* >>> df.width
|
|
995
1153
|
* 2
|
|
996
1154
|
*/
|
|
997
1155
|
get width(): number;
|
|
998
|
-
private _normalizeArgs;
|
|
999
1156
|
/**
|
|
1000
1157
|
* Adds new columns or updates existing ones using column expressions.
|
|
1001
1158
|
* @param {(string | IExpr | Record<string, any> | (string | IExpr | Record<string, any>)[])[]} args Expressions or field objects defining column calculations.
|
|
1002
1159
|
* @returns {DataFrame}
|
|
1003
1160
|
* @example
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
* >>> df.
|
|
1014
|
-
* shape: (2,
|
|
1015
|
-
*
|
|
1016
|
-
* │ a │ b
|
|
1017
|
-
*
|
|
1018
|
-
* │ 1 │
|
|
1019
|
-
* │ 2 │
|
|
1020
|
-
*
|
|
1161
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
1162
|
+
* >>> df
|
|
1163
|
+
* shape: (2, 2)
|
|
1164
|
+
* ┌───┬───┐
|
|
1165
|
+
* │ a │ b │
|
|
1166
|
+
* ├───┼───┤
|
|
1167
|
+
* │ 1 │ x │
|
|
1168
|
+
* │ 2 │ y │
|
|
1169
|
+
* └───┴───┘
|
|
1170
|
+
* >>> df.withColumns($df.col("a").mul(10).alias("a_x10"))
|
|
1171
|
+
* shape: (2, 3)
|
|
1172
|
+
* ┌───┬───┬───────┐
|
|
1173
|
+
* │ a │ b │ a_x10 │
|
|
1174
|
+
* ├───┼───┼───────┤
|
|
1175
|
+
* │ 1 │ x │ 10 │
|
|
1176
|
+
* │ 2 │ y │ 20 │
|
|
1177
|
+
* └───┴───┴───────┘
|
|
1021
1178
|
*/
|
|
1022
|
-
|
|
1179
|
+
withColumns(...args: (string | IExpr | Record<string, any> | (string | IExpr | Record<string, any>)[])[]): DataFrame<any>;
|
|
1023
1180
|
/**
|
|
1024
1181
|
* Appends an incremental index column.
|
|
1025
1182
|
* @param {string} [name] Name of index column (default "index").
|
|
1026
1183
|
* @param {number} [offset] Starting numeric index offset (default 0).
|
|
1027
1184
|
* @returns {DataFrame}
|
|
1028
1185
|
* @example
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
* >>> df.
|
|
1039
|
-
* shape: (2,
|
|
1040
|
-
*
|
|
1041
|
-
* │ idx │
|
|
1042
|
-
*
|
|
1043
|
-
* │ 0 │
|
|
1044
|
-
* │ 1 │
|
|
1045
|
-
*
|
|
1186
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
1187
|
+
* >>> df
|
|
1188
|
+
* shape: (2, 2)
|
|
1189
|
+
* ┌───┬───┐
|
|
1190
|
+
* │ a │ b │
|
|
1191
|
+
* ├───┼───┤
|
|
1192
|
+
* │ 1 │ x │
|
|
1193
|
+
* │ 2 │ y │
|
|
1194
|
+
* └───┴───┘
|
|
1195
|
+
* >>> df.withRowIndex("idx")
|
|
1196
|
+
* shape: (2, 3)
|
|
1197
|
+
* ┌─────┬───┬───┐
|
|
1198
|
+
* │ idx │ a │ b │
|
|
1199
|
+
* ├─────┼───┼───┤
|
|
1200
|
+
* │ 0 │ 1 │ x │
|
|
1201
|
+
* │ 1 │ 2 │ y │
|
|
1202
|
+
* └─────┴───┴───┘
|
|
1203
|
+
*/
|
|
1204
|
+
withRowIndex(name?: string, offset?: number): DataFrame<any>;
|
|
1205
|
+
/**
|
|
1206
|
+
* Writes DataFrame to CSV format string or file/stream target.
|
|
1207
|
+
* @note [Environment]: When `file` is provided as a string file path, execution requires a Node.js-compatible
|
|
1208
|
+
* environment with `fs` access. In browser environments, omit `file` to receive a string or supply a custom writable stream object.
|
|
1209
|
+
* @param {string | { write: (str: string) => void }} [file] Target file path or writable stream target (optional).
|
|
1210
|
+
* @param {WriteCSVOptions} [options] CSV formatting options.
|
|
1211
|
+
* @param {string} [options.delimiter] Column delimiter character (default `","`).
|
|
1212
|
+
* @param {boolean} [options.header] When `true` (default), includes column header row.
|
|
1213
|
+
* @param {string} [options.quoteChar] Character used to enclose fields containing special characters (default `'"'`).
|
|
1214
|
+
* @returns {string} CSV string output.
|
|
1215
|
+
* @example
|
|
1216
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
1217
|
+
* >>> df
|
|
1218
|
+
* shape: (2, 2)
|
|
1219
|
+
* ┌───┬───┐
|
|
1220
|
+
* │ a │ b │
|
|
1221
|
+
* ├───┼───┤
|
|
1222
|
+
* │ 1 │ x │
|
|
1223
|
+
* │ 2 │ y │
|
|
1224
|
+
* └───┴───┘
|
|
1225
|
+
* >>> df.writeCsv()
|
|
1226
|
+
* "a,b\n1,x"
|
|
1046
1227
|
*/
|
|
1047
|
-
|
|
1228
|
+
writeCsv(file?: string | {
|
|
1229
|
+
write: (str: string) => void;
|
|
1230
|
+
}, options?: WriteCSVOptions): string;
|
|
1048
1231
|
/**
|
|
1049
1232
|
* Writes DataFrame rows to JSON format string or file/stream target.
|
|
1233
|
+
* @note [Environment]: When `file` is provided as a string file path, execution requires a Node.js-compatible
|
|
1234
|
+
* environment with `fs` access. In browser environments, omit `file` to receive a string or supply a custom writable stream object.
|
|
1050
1235
|
* @param {string | { write: (str: string) => void }} [file] Target file path or writable stream target (optional).
|
|
1051
1236
|
* @param {WriteJSONOptions} [options] JSON formatting and replacer options.
|
|
1052
1237
|
* @param {JSONFormat} [options.format] JSON output format structure (`"json"` or `"ndjson"`). Default `"json"`.
|
|
@@ -1073,41 +1258,19 @@ export declare class DataFrame<T extends RowRecord = any> {
|
|
|
1073
1258
|
* @param {((this: any, k: string, v: any) => any) | (string | number)[] | null} [options.replacerOptions.replacer] Custom replacer function or array whitelist that runs first for pre-processing.
|
|
1074
1259
|
* @returns {string} JSON string representation.
|
|
1075
1260
|
* @example
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1261
|
+
* >>> const df = $df.data({ a: [1, 2], b: ["x", "y"] })
|
|
1262
|
+
* >>> df
|
|
1263
|
+
* shape: (2, 2)
|
|
1264
|
+
* ┌───┬───┐
|
|
1265
|
+
* │ a │ b │
|
|
1266
|
+
* ├───┼───┤
|
|
1267
|
+
* │ 1 │ x │
|
|
1268
|
+
* │ 2 │ y │
|
|
1269
|
+
* └───┴───┘
|
|
1270
|
+
* >>> df.writeJson()
|
|
1085
1271
|
* '[{"a":1,"b":"x"}]'
|
|
1086
1272
|
*/
|
|
1087
|
-
|
|
1273
|
+
writeJson(file?: string | {
|
|
1088
1274
|
write: (str: string) => void;
|
|
1089
1275
|
}, { format, replacerOptions }?: WriteJSONOptions): string;
|
|
1090
|
-
/**
|
|
1091
|
-
* Writes DataFrame to CSV format string or file/stream target.
|
|
1092
|
-
* @param {string | { write: (str: string) => void }} [file] Target file path or writable stream target (optional).
|
|
1093
|
-
* @param {WriteCSVOptions} [options] CSV formatting options.
|
|
1094
|
-
* @param {string} [options.delimiter] Column delimiter character (default `","`).
|
|
1095
|
-
* @param {boolean} [options.header] When `true` (default), includes column header row.
|
|
1096
|
-
* @param {string} [options.quoteChar] Character used to enclose fields containing special characters (default `'"'`).
|
|
1097
|
-
* @returns {string} CSV string output.
|
|
1098
|
-
* @example
|
|
1099
|
-
* >>> const df = $df.data({ a: [1], b: ["x"] })
|
|
1100
|
-
* >>> df
|
|
1101
|
-
* shape: (1, 2)
|
|
1102
|
-
* ┌───┬───┐
|
|
1103
|
-
* │ a │ b │
|
|
1104
|
-
* ├───┼───┤
|
|
1105
|
-
* │ 1 │ x │
|
|
1106
|
-
* └───┴───┘
|
|
1107
|
-
* >>> df.write_csv()
|
|
1108
|
-
* "a,b\n1,x"
|
|
1109
|
-
*/
|
|
1110
|
-
write_csv(file?: string | {
|
|
1111
|
-
write: (str: string) => void;
|
|
1112
|
-
}, options?: WriteCSVOptions): string;
|
|
1113
1276
|
}
|