@ohos-ports/nodejs-polars 0.22.2-beta.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/LICENSE +19 -0
- package/README.md +217 -0
- package/bin/cfg.d.ts +156 -0
- package/bin/cfg.js +52 -0
- package/bin/dataframe.d.ts +2008 -0
- package/bin/dataframe.js +771 -0
- package/bin/datatypes/conversion.d.ts +2 -0
- package/bin/datatypes/conversion.js +2 -0
- package/bin/datatypes/datatype.d.ts +252 -0
- package/bin/datatypes/datatype.js +386 -0
- package/bin/datatypes/field.d.ts +26 -0
- package/bin/datatypes/field.js +36 -0
- package/bin/datatypes/index.d.ts +42 -0
- package/bin/datatypes/index.js +119 -0
- package/bin/error.d.ts +7 -0
- package/bin/error.js +17 -0
- package/bin/functions.d.ts +26 -0
- package/bin/functions.js +208 -0
- package/bin/groupby.d.ts +173 -0
- package/bin/groupby.js +156 -0
- package/bin/html.d.ts +4 -0
- package/bin/html.js +18 -0
- package/bin/index.d.ts +252 -0
- package/bin/index.js +265 -0
- package/bin/internals/construction.d.ts +7 -0
- package/bin/internals/construction.js +237 -0
- package/bin/internals/polars_internal.d.ts +2 -0
- package/bin/internals/polars_internal.js +7 -0
- package/bin/io.d.ts +421 -0
- package/bin/io.js +332 -0
- package/bin/lazy/dataframe.d.ts +693 -0
- package/bin/lazy/dataframe.js +421 -0
- package/bin/lazy/expr/datetime.d.ts +8 -0
- package/bin/lazy/expr/datetime.js +25 -0
- package/bin/lazy/expr/index.d.ts +1155 -0
- package/bin/lazy/expr/index.js +629 -0
- package/bin/lazy/expr/list.d.ts +8 -0
- package/bin/lazy/expr/list.js +115 -0
- package/bin/lazy/expr/string.d.ts +534 -0
- package/bin/lazy/expr/string.js +131 -0
- package/bin/lazy/expr/struct.d.ts +126 -0
- package/bin/lazy/expr/struct.js +26 -0
- package/bin/lazy/functions.d.ts +620 -0
- package/bin/lazy/functions.js +691 -0
- package/bin/lazy/groupby.d.ts +24 -0
- package/bin/lazy/groupby.js +22 -0
- package/bin/lazy/index.d.ts +4 -0
- package/bin/lazy/index.js +20 -0
- package/bin/lazy/whenthen.d.ts +67 -0
- package/bin/lazy/whenthen.js +81 -0
- package/bin/native-polars.d.ts +2 -0
- package/bin/native-polars.js +267 -0
- package/bin/series/datetime.d.ts +8 -0
- package/bin/series/datetime.js +25 -0
- package/bin/series/index.d.ts +1116 -0
- package/bin/series/index.js +689 -0
- package/bin/series/list.d.ts +8 -0
- package/bin/series/list.js +87 -0
- package/bin/series/string.d.ts +300 -0
- package/bin/series/string.js +125 -0
- package/bin/series/struct.d.ts +36 -0
- package/bin/series/struct.js +35 -0
- package/bin/shared_traits.d.ts +1325 -0
- package/bin/shared_traits.js +2 -0
- package/bin/sql.d.ts +244 -0
- package/bin/sql.js +63 -0
- package/bin/types.d.ts +284 -0
- package/bin/types.js +2 -0
- package/bin/utils.d.ts +38 -0
- package/bin/utils.js +69 -0
- package/package.json +51 -0
|
@@ -0,0 +1,2008 @@
|
|
|
1
|
+
import { Writable } from "node:stream";
|
|
2
|
+
import { DataType, type DTypeToJs, type JsToDtype } from "./datatypes";
|
|
3
|
+
import { type GroupBy, RollingGroupBy } from "./groupby";
|
|
4
|
+
import { type LazyDataFrame } from "./lazy/dataframe";
|
|
5
|
+
import { Expr } from "./lazy/expr";
|
|
6
|
+
import { Series } from "./series";
|
|
7
|
+
import type { Arithmetic, Deserialize, GroupByOps, Sample, Serialize } from "./shared_traits";
|
|
8
|
+
import type { CrossJoinOptions, CsvWriterOptions, DifferentNameColumnJoinOptions, FillNullStrategy, JoinOptions, SameNameColumnJoinOptions, WriteAvroOptions, WriteIPCOptions, WriteParquetOptions } from "./types";
|
|
9
|
+
import { type ColumnSelection, type ColumnsOrExpr, type ExprOrString, type Simplify } from "./utils";
|
|
10
|
+
declare const inspect: unique symbol;
|
|
11
|
+
export declare const writeCsvDefaultOptions: Partial<CsvWriterOptions>;
|
|
12
|
+
/**
|
|
13
|
+
* Write methods for DataFrame
|
|
14
|
+
*/
|
|
15
|
+
interface WriteMethods {
|
|
16
|
+
/**
|
|
17
|
+
* __Write DataFrame to comma-separated values file (csv).__
|
|
18
|
+
*
|
|
19
|
+
* If no options are specified, it will return a new string containing the contents
|
|
20
|
+
* ___
|
|
21
|
+
* @param dest file or stream to write to
|
|
22
|
+
* @param options.includeBom - Whether to include UTF-8 BOM in the CSV output.
|
|
23
|
+
* @param options.lineTerminator - String used to end each row.
|
|
24
|
+
* @param options.includeHeader - Whether or not to include header in the CSV output.
|
|
25
|
+
* @param options.separator - Separate CSV fields with this symbol. Defaults: `,`
|
|
26
|
+
* @param options.quoteChar - Character to use for quoting. Default: '"'
|
|
27
|
+
* @param options.batchSize - Number of rows that will be processed per thread.
|
|
28
|
+
* @param options.datetimeFormat - A format string, with the specifiers defined by the
|
|
29
|
+
* `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
|
|
30
|
+
* Rust crate. If no format specified, the default fractional-second
|
|
31
|
+
* precision is inferred from the maximum timeunit found in the frame's
|
|
32
|
+
* Datetime cols (if any).
|
|
33
|
+
* @param options.dateFormat - A format string, with the specifiers defined by the
|
|
34
|
+
* `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
|
|
35
|
+
* Rust crate.
|
|
36
|
+
* @param options.timeFormat A format string, with the specifiers defined by the
|
|
37
|
+
* `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
|
|
38
|
+
* Rust crate.
|
|
39
|
+
* @param options.floatPrecision - Number of decimal places to write, applied to both `Float32` and `Float64` datatypes.
|
|
40
|
+
* @param options.nullValue - A string representing null values (defaulting to the empty string).
|
|
41
|
+
* @example
|
|
42
|
+
* ```
|
|
43
|
+
* > const df = pl.DataFrame({
|
|
44
|
+
* ... "foo": [1, 2, 3],
|
|
45
|
+
* ... "bar": [6, 7, 8],
|
|
46
|
+
* ... "ham": ['a', 'b', 'c']
|
|
47
|
+
* ... });
|
|
48
|
+
* > df.writeCSV();
|
|
49
|
+
* foo,bar,ham
|
|
50
|
+
* 1,6,a
|
|
51
|
+
* 2,7,b
|
|
52
|
+
* 3,8,c
|
|
53
|
+
*
|
|
54
|
+
* // using a file path
|
|
55
|
+
* > df.head(1).writeCSV("./foo.csv")
|
|
56
|
+
* // foo.csv
|
|
57
|
+
* foo,bar,ham
|
|
58
|
+
* 1,6,a
|
|
59
|
+
*
|
|
60
|
+
* // using a write stream
|
|
61
|
+
* > const writeStream = new Stream.Writable({
|
|
62
|
+
* ... write(chunk, encoding, callback) {
|
|
63
|
+
* ... console.log("writeStream: %O', chunk.toString());
|
|
64
|
+
* ... callback(null);
|
|
65
|
+
* ... }
|
|
66
|
+
* ... });
|
|
67
|
+
* > df.head(1).writeCSV(writeStream, {includeHeader: false});
|
|
68
|
+
* writeStream: '1,6,a'
|
|
69
|
+
* ```
|
|
70
|
+
* @category IO
|
|
71
|
+
*/
|
|
72
|
+
writeCSV(dest: string | Writable, options?: CsvWriterOptions): void;
|
|
73
|
+
writeCSV(): Buffer;
|
|
74
|
+
writeCSV(options: CsvWriterOptions): Buffer;
|
|
75
|
+
/**
|
|
76
|
+
* Write Dataframe to JSON string, file, or write stream
|
|
77
|
+
* @param destination file or write stream
|
|
78
|
+
* @param options.format - json | lines
|
|
79
|
+
* @example
|
|
80
|
+
* ```
|
|
81
|
+
* > const df = pl.DataFrame({
|
|
82
|
+
* ... foo: [1,2,3],
|
|
83
|
+
* ... bar: ['a','b','c']
|
|
84
|
+
* ... })
|
|
85
|
+
*
|
|
86
|
+
* > df.writeJSON({format:"json"})
|
|
87
|
+
* `[ {"foo":1.0,"bar":"a"}, {"foo":2.0,"bar":"b"}, {"foo":3.0,"bar":"c"}]`
|
|
88
|
+
*
|
|
89
|
+
* > df.writeJSON({format:"lines"})
|
|
90
|
+
* `{"foo":1.0,"bar":"a"}
|
|
91
|
+
* {"foo":2.0,"bar":"b"}
|
|
92
|
+
* {"foo":3.0,"bar":"c"}`
|
|
93
|
+
*
|
|
94
|
+
* // writing to a file
|
|
95
|
+
* > df.writeJSON("/path/to/file.json", {format:'lines'})
|
|
96
|
+
* ```
|
|
97
|
+
* @category IO
|
|
98
|
+
*/
|
|
99
|
+
writeJSON(destination: string | Writable, options?: {
|
|
100
|
+
format: "lines" | "json";
|
|
101
|
+
}): void;
|
|
102
|
+
writeJSON(options?: {
|
|
103
|
+
format: "lines" | "json";
|
|
104
|
+
}): Buffer;
|
|
105
|
+
/**
|
|
106
|
+
* Write to Arrow IPC feather file, either to a file path or to a write stream.
|
|
107
|
+
* @param destination File path to which the file should be written, or writable.
|
|
108
|
+
* @param options.compression Compression method *defaults to "uncompressed"*
|
|
109
|
+
* @category IO
|
|
110
|
+
*/
|
|
111
|
+
writeIPC(destination: string | Writable, options?: WriteIPCOptions): void;
|
|
112
|
+
writeIPC(options?: WriteIPCOptions): Buffer;
|
|
113
|
+
/**
|
|
114
|
+
* Write to Arrow IPC stream file, either to a file path or to a write stream.
|
|
115
|
+
* @param destination File path to which the file should be written, or writable.
|
|
116
|
+
* @param options.compression Compression method *defaults to "uncompressed"*
|
|
117
|
+
* @category IO
|
|
118
|
+
*/
|
|
119
|
+
writeIPCStream(destination: string | Writable, options?: WriteIPCOptions): void;
|
|
120
|
+
writeIPCStream(options?: WriteIPCOptions): Buffer;
|
|
121
|
+
/**
|
|
122
|
+
* Write the DataFrame disk in parquet format.
|
|
123
|
+
* @param destination File path to which the file should be written, or writable.
|
|
124
|
+
* @param options.compression Compression method *defaults to "uncompressed"*
|
|
125
|
+
* @category IO
|
|
126
|
+
*/
|
|
127
|
+
writeParquet(destination: string | Writable, options?: WriteParquetOptions): void;
|
|
128
|
+
writeParquet(options?: WriteParquetOptions): Buffer;
|
|
129
|
+
/**
|
|
130
|
+
* Write the DataFrame disk in avro format.
|
|
131
|
+
* @param destination File path to which the file should be written, or writable.
|
|
132
|
+
* @param options.compression Compression method *defaults to "uncompressed"*
|
|
133
|
+
* @category IO
|
|
134
|
+
*/
|
|
135
|
+
writeAvro(destination: string | Writable, options?: WriteAvroOptions): void;
|
|
136
|
+
writeAvro(options?: WriteAvroOptions): Buffer;
|
|
137
|
+
}
|
|
138
|
+
export type Schema = Record<string, DataType>;
|
|
139
|
+
type SchemaToSeriesRecord<T extends Record<string, DataType>> = {
|
|
140
|
+
[K in keyof T]: K extends string ? Series<T[K], K> : never;
|
|
141
|
+
};
|
|
142
|
+
type ArrayLikeLooseRecordToSchema<T extends Record<string, ArrayLike<any>>> = {
|
|
143
|
+
[K in keyof T]: K extends string | number ? T[K] extends ArrayLike<infer V> ? V extends DataType ? V : JsToDtype<V> : never : never;
|
|
144
|
+
};
|
|
145
|
+
type ExtractJoinKeys<T> = T extends string[] ? T[number] : T;
|
|
146
|
+
type ExtractSuffix<T extends JoinOptions> = T extends {
|
|
147
|
+
suffix: infer Suffix;
|
|
148
|
+
} ? Suffix : "_right";
|
|
149
|
+
export type JoinSchemas<S1 extends Schema, S2 extends Schema, Opt extends JoinOptions> = Simplify<{
|
|
150
|
+
[K1 in keyof S1]: S1[K1];
|
|
151
|
+
} & {
|
|
152
|
+
[K2 in Exclude<keyof S2, keyof S1>]: K2 extends keyof S1 ? never : S2[K2];
|
|
153
|
+
} & {
|
|
154
|
+
[K_SUFFIXED in keyof S1 & Exclude<keyof S2, Opt extends CrossJoinOptions ? never : Opt extends SameNameColumnJoinOptions ? ExtractJoinKeys<Opt["on"]> : Opt extends DifferentNameColumnJoinOptions ? ExtractJoinKeys<Opt["rightOn"]> : never> as `${K_SUFFIXED extends string ? K_SUFFIXED : never}${ExtractSuffix<Opt>}`]: K_SUFFIXED extends string ? S2[K_SUFFIXED] : never;
|
|
155
|
+
}>;
|
|
156
|
+
/**
|
|
157
|
+
* A DataFrame is a two-dimensional data structure that represents data as a table
|
|
158
|
+
* with rows and columns.
|
|
159
|
+
*
|
|
160
|
+
* @param data - Object, Array, or Series
|
|
161
|
+
* Two-dimensional data in various forms. object must contain Arrays.
|
|
162
|
+
* Array may contain Series or other Arrays.
|
|
163
|
+
* @param columns - Array of str, default undefined
|
|
164
|
+
* Column labels to use for resulting DataFrame. If specified, overrides any
|
|
165
|
+
* labels already present in the data. Must match data dimensions.
|
|
166
|
+
* @param orient - 'col' | 'row' default undefined
|
|
167
|
+
* Whether to interpret two-dimensional data as columns or as rows. If None,
|
|
168
|
+
* the orientation is inferred by matching the columns and data dimensions. If
|
|
169
|
+
* this does not yield conclusive results, column orientation is used.
|
|
170
|
+
* @example
|
|
171
|
+
* Constructing a DataFrame from an object :
|
|
172
|
+
* ```
|
|
173
|
+
* > const data = {'a': [1n, 2n], 'b': [3, 4]};
|
|
174
|
+
* > const df = pl.DataFrame(data);
|
|
175
|
+
* > console.log(df.toString());
|
|
176
|
+
* shape: (2, 2)
|
|
177
|
+
* ╭─────┬─────╮
|
|
178
|
+
* │ a ┆ b │
|
|
179
|
+
* │ --- ┆ --- │
|
|
180
|
+
* │ u64 ┆ i64 │
|
|
181
|
+
* ╞═════╪═════╡
|
|
182
|
+
* │ 1 ┆ 3 │
|
|
183
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
184
|
+
* │ 2 ┆ 4 │
|
|
185
|
+
* ╰─────┴─────╯
|
|
186
|
+
* ```
|
|
187
|
+
* Notice that the dtype is automatically inferred as a polars Int64:
|
|
188
|
+
* ```
|
|
189
|
+
* > df.dtypes
|
|
190
|
+
* ['UInt64', `Int64']
|
|
191
|
+
* ```
|
|
192
|
+
* In order to specify dtypes for your columns, initialize the DataFrame with a list
|
|
193
|
+
* of Series instead:
|
|
194
|
+
* ```
|
|
195
|
+
* > const data = [pl.Series('col1', [1, 2], pl.Float32), pl.Series('col2', [3, 4], pl.Int64)];
|
|
196
|
+
* > const df2 = pl.DataFrame(series);
|
|
197
|
+
* > console.log(df2.toString());
|
|
198
|
+
* shape: (2, 2)
|
|
199
|
+
* ╭──────┬──────╮
|
|
200
|
+
* │ col1 ┆ col2 │
|
|
201
|
+
* │ --- ┆ --- │
|
|
202
|
+
* │ f32 ┆ i64 │
|
|
203
|
+
* ╞══════╪══════╡
|
|
204
|
+
* │ 1 ┆ 3 │
|
|
205
|
+
* ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
206
|
+
* │ 2 ┆ 4 │
|
|
207
|
+
* ╰──────┴──────╯
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* Constructing a DataFrame from a list of lists, row orientation inferred:
|
|
211
|
+
* ```
|
|
212
|
+
* > const data = [[1, 2, 3], [4, 5, 6]];
|
|
213
|
+
* > const df4 = pl.DataFrame(data, ['a', 'b', 'c']);
|
|
214
|
+
* > console.log(df4.toString());
|
|
215
|
+
* shape: (2, 3)
|
|
216
|
+
* ╭─────┬─────┬─────╮
|
|
217
|
+
* │ a ┆ b ┆ c │
|
|
218
|
+
* │ --- ┆ --- ┆ --- │
|
|
219
|
+
* │ i64 ┆ i64 ┆ i64 │
|
|
220
|
+
* ╞═════╪═════╪═════╡
|
|
221
|
+
* │ 1 ┆ 2 ┆ 3 │
|
|
222
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
223
|
+
* │ 4 ┆ 5 ┆ 6 │
|
|
224
|
+
* ╰─────┴─────┴─────╯
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
export interface DataFrame<S extends Schema = any> extends Arithmetic<DataFrame<S>>, Sample<DataFrame<S>>, WriteMethods, Serialize, GroupByOps<RollingGroupBy> {
|
|
228
|
+
/** @ignore */
|
|
229
|
+
_df: any;
|
|
230
|
+
dtypes: DataType[];
|
|
231
|
+
height: number;
|
|
232
|
+
shape: {
|
|
233
|
+
height: number;
|
|
234
|
+
width: number;
|
|
235
|
+
};
|
|
236
|
+
width: number;
|
|
237
|
+
get columns(): string[];
|
|
238
|
+
set columns(cols: string[]);
|
|
239
|
+
[inspect](): string;
|
|
240
|
+
[Symbol.iterator](): Generator<any, void, any>;
|
|
241
|
+
/**
|
|
242
|
+
* Very cheap deep clone.
|
|
243
|
+
*/
|
|
244
|
+
clone(): DataFrame<S>;
|
|
245
|
+
/**
|
|
246
|
+
* __Summary statistics for a DataFrame.__
|
|
247
|
+
*
|
|
248
|
+
* Only summarizes numeric datatypes at the moment and returns nulls for non numeric datatypes.
|
|
249
|
+
* ___
|
|
250
|
+
* Example
|
|
251
|
+
* ```
|
|
252
|
+
* > const df = pl.DataFrame({
|
|
253
|
+
* ... 'a': [1.0, 2.8, 3.0],
|
|
254
|
+
* ... 'b': [4, 5, 6],
|
|
255
|
+
* ... "c": [True, False, True]
|
|
256
|
+
* ... });
|
|
257
|
+
* ... df.describe()
|
|
258
|
+
* shape: (5, 4)
|
|
259
|
+
* ╭──────────┬───────┬─────┬──────╮
|
|
260
|
+
* │ describe ┆ a ┆ b ┆ c │
|
|
261
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
262
|
+
* │ str ┆ f64 ┆ f64 ┆ f64 │
|
|
263
|
+
* ╞══════════╪═══════╪═════╪══════╡
|
|
264
|
+
* │ "mean" ┆ 2.267 ┆ 5 ┆ null │
|
|
265
|
+
* ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
266
|
+
* │ "std" ┆ 1.102 ┆ 1 ┆ null │
|
|
267
|
+
* ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
268
|
+
* │ "min" ┆ 1 ┆ 4 ┆ 0.0 │
|
|
269
|
+
* ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
270
|
+
* │ "max" ┆ 3 ┆ 6 ┆ 1 │
|
|
271
|
+
* ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
272
|
+
* │ "median" ┆ 2.8 ┆ 5 ┆ null │
|
|
273
|
+
* ╰──────────┴───────┴─────┴──────╯
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
describe(): DataFrame;
|
|
277
|
+
/**
|
|
278
|
+
* __Remove column from DataFrame and return as new.__
|
|
279
|
+
* ___
|
|
280
|
+
* @param name
|
|
281
|
+
* @example
|
|
282
|
+
* ```
|
|
283
|
+
* > const df = pl.DataFrame({
|
|
284
|
+
* ... "foo": [1, 2, 3],
|
|
285
|
+
* ... "bar": [6.0, 7.0, 8.0],
|
|
286
|
+
* ... "ham": ['a', 'b', 'c'],
|
|
287
|
+
* ... "apple": ['a', 'b', 'c']
|
|
288
|
+
* ... });
|
|
289
|
+
* // df: pl.DataFrame<{
|
|
290
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
291
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
292
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
293
|
+
* // apple: pl.Series<Utf8, "apple">;
|
|
294
|
+
* // }>
|
|
295
|
+
* > const df2 = df.drop(['ham', 'apple']);
|
|
296
|
+
* // df2: pl.DataFrame<{
|
|
297
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
298
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
299
|
+
* // }>
|
|
300
|
+
* > console.log(df2.toString());
|
|
301
|
+
* shape: (3, 2)
|
|
302
|
+
* ╭─────┬─────╮
|
|
303
|
+
* │ foo ┆ bar │
|
|
304
|
+
* │ --- ┆ --- │
|
|
305
|
+
* │ i64 ┆ f64 │
|
|
306
|
+
* ╞═════╪═════╡
|
|
307
|
+
* │ 1 ┆ 6 │
|
|
308
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
309
|
+
* │ 2 ┆ 7 │
|
|
310
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
311
|
+
* │ 3 ┆ 8 │
|
|
312
|
+
* ╰─────┴─────╯
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
drop<U extends string>(name: U): DataFrame<Simplify<Omit<S, U>>>;
|
|
316
|
+
drop<const U extends string[]>(names: U): DataFrame<Simplify<Omit<S, U[number]>>>;
|
|
317
|
+
drop<U extends string, const V extends string[]>(name: U, ...names: V): DataFrame<Simplify<Omit<S, U | V[number]>>>;
|
|
318
|
+
/**
|
|
319
|
+
* __Return a new DataFrame where the null values are dropped.__
|
|
320
|
+
*
|
|
321
|
+
* This method only drops nulls row-wise if any single value of the row is null.
|
|
322
|
+
* ___
|
|
323
|
+
* @example
|
|
324
|
+
* ```
|
|
325
|
+
* > const df = pl.DataFrame({
|
|
326
|
+
* ... "foo": [1, 2, 3],
|
|
327
|
+
* ... "bar": [6, null, 8],
|
|
328
|
+
* ... "ham": ['a', 'b', 'c']
|
|
329
|
+
* ... });
|
|
330
|
+
* > console.log(df.dropNulls().toString());
|
|
331
|
+
* shape: (2, 3)
|
|
332
|
+
* ┌─────┬─────┬─────┐
|
|
333
|
+
* │ foo ┆ bar ┆ ham │
|
|
334
|
+
* │ --- ┆ --- ┆ --- │
|
|
335
|
+
* │ i64 ┆ i64 ┆ str │
|
|
336
|
+
* ╞═════╪═════╪═════╡
|
|
337
|
+
* │ 1 ┆ 6 ┆ "a" │
|
|
338
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
339
|
+
* │ 3 ┆ 8 ┆ "c" │
|
|
340
|
+
* └─────┴─────┴─────┘
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
dropNulls(column: keyof S): DataFrame<S>;
|
|
344
|
+
dropNulls(columns: (keyof S)[]): DataFrame<S>;
|
|
345
|
+
dropNulls(...columns: (keyof S)[]): DataFrame<S>;
|
|
346
|
+
/**
|
|
347
|
+
* __Explode `DataFrame` to long format by exploding a column with Lists.__
|
|
348
|
+
* ___
|
|
349
|
+
* @param columns - column or columns to explode
|
|
350
|
+
* @example
|
|
351
|
+
* ```
|
|
352
|
+
* > const df = pl.DataFrame({
|
|
353
|
+
* ... "letters": ["c", "c", "a", "c", "a", "b"],
|
|
354
|
+
* ... "nrs": [[1, 2], [1, 3], [4, 3], [5, 5, 5], [6], [2, 1, 2]]
|
|
355
|
+
* ... });
|
|
356
|
+
* > console.log(df.toString());
|
|
357
|
+
* shape: (6, 2)
|
|
358
|
+
* ╭─────────┬────────────╮
|
|
359
|
+
* │ letters ┆ nrs │
|
|
360
|
+
* │ --- ┆ --- │
|
|
361
|
+
* │ str ┆ list [i64] │
|
|
362
|
+
* ╞═════════╪════════════╡
|
|
363
|
+
* │ "c" ┆ [1, 2] │
|
|
364
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
365
|
+
* │ "c" ┆ [1, 3] │
|
|
366
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
367
|
+
* │ "a" ┆ [4, 3] │
|
|
368
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
369
|
+
* │ "c" ┆ [5, 5, 5] │
|
|
370
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
371
|
+
* │ "a" ┆ [6] │
|
|
372
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
373
|
+
* │ "b" ┆ [2, 1, 2] │
|
|
374
|
+
* ╰─────────┴────────────╯
|
|
375
|
+
* > df.explode("nrs")
|
|
376
|
+
* shape: (13, 2)
|
|
377
|
+
* ╭─────────┬─────╮
|
|
378
|
+
* │ letters ┆ nrs │
|
|
379
|
+
* │ --- ┆ --- │
|
|
380
|
+
* │ str ┆ i64 │
|
|
381
|
+
* ╞═════════╪═════╡
|
|
382
|
+
* │ "c" ┆ 1 │
|
|
383
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
384
|
+
* │ "c" ┆ 2 │
|
|
385
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
386
|
+
* │ "c" ┆ 1 │
|
|
387
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
388
|
+
* │ "c" ┆ 3 │
|
|
389
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
390
|
+
* │ ... ┆ ... │
|
|
391
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
392
|
+
* │ "c" ┆ 5 │
|
|
393
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
394
|
+
* │ "a" ┆ 6 │
|
|
395
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
396
|
+
* │ "b" ┆ 2 │
|
|
397
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
398
|
+
* │ "b" ┆ 1 │
|
|
399
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
400
|
+
* │ "b" ┆ 2 │
|
|
401
|
+
* ╰─────────┴─────╯
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
explode(columns: ExprOrString[]): DataFrame;
|
|
405
|
+
explode(column: ExprOrString): DataFrame;
|
|
406
|
+
explode(column: ExprOrString, ...columns: ExprOrString[]): DataFrame;
|
|
407
|
+
/**
|
|
408
|
+
*
|
|
409
|
+
*
|
|
410
|
+
* __Extend the memory backed by this `DataFrame` with the values from `other`.__
|
|
411
|
+
* ___
|
|
412
|
+
|
|
413
|
+
Different from `vstack` which adds the chunks from `other` to the chunks of this `DataFrame`
|
|
414
|
+
`extent` appends the data from `other` to the underlying memory locations and thus may cause a reallocation.
|
|
415
|
+
|
|
416
|
+
If this does not cause a reallocation, the resulting data structure will not have any extra chunks
|
|
417
|
+
and thus will yield faster queries.
|
|
418
|
+
|
|
419
|
+
Prefer `extend` over `vstack` when you want to do a query after a single append. For instance during
|
|
420
|
+
online operations where you add `n` rows and rerun a query.
|
|
421
|
+
|
|
422
|
+
Prefer `vstack` over `extend` when you want to append many times before doing a query. For instance
|
|
423
|
+
when you read in multiple files and when to store them in a single `DataFrame`.
|
|
424
|
+
In the latter case, finish the sequence of `vstack` operations with a `rechunk`.
|
|
425
|
+
|
|
426
|
+
* @param other DataFrame to vertically add.
|
|
427
|
+
*/
|
|
428
|
+
extend(other: DataFrame<S>): DataFrame<S>;
|
|
429
|
+
/**
|
|
430
|
+
* Fill null/missing values by a filling strategy
|
|
431
|
+
*
|
|
432
|
+
* @param strategy - One of:
|
|
433
|
+
* - "backward"
|
|
434
|
+
* - "forward"
|
|
435
|
+
* - "mean"
|
|
436
|
+
* - "min'
|
|
437
|
+
* - "max"
|
|
438
|
+
* - "zero"
|
|
439
|
+
* - "one"
|
|
440
|
+
* @returns DataFrame with None replaced with the filling strategy.
|
|
441
|
+
*/
|
|
442
|
+
fillNull(strategy: FillNullStrategy): DataFrame<S>;
|
|
443
|
+
/**
|
|
444
|
+
* Filter the rows in the DataFrame based on a predicate expression.
|
|
445
|
+
* ___
|
|
446
|
+
* @param predicate - Expression that evaluates to a boolean Series.
|
|
447
|
+
* @example
|
|
448
|
+
* ```
|
|
449
|
+
* > const df = pl.DataFrame({
|
|
450
|
+
* ... "foo": [1, 2, 3],
|
|
451
|
+
* ... "bar": [6, 7, 8],
|
|
452
|
+
* ... "ham": ['a', 'b', 'c']
|
|
453
|
+
* ... });
|
|
454
|
+
* // Filter on one condition
|
|
455
|
+
* > df.filter(pl.col("foo").lt(3))
|
|
456
|
+
* shape: (2, 3)
|
|
457
|
+
* ┌─────┬─────┬─────┐
|
|
458
|
+
* │ foo ┆ bar ┆ ham │
|
|
459
|
+
* │ --- ┆ --- ┆ --- │
|
|
460
|
+
* │ i64 ┆ i64 ┆ str │
|
|
461
|
+
* ╞═════╪═════╪═════╡
|
|
462
|
+
* │ 1 ┆ 6 ┆ a │
|
|
463
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
464
|
+
* │ 2 ┆ 7 ┆ b │
|
|
465
|
+
* └─────┴─────┴─────┘
|
|
466
|
+
* // Filter on multiple conditions
|
|
467
|
+
* > df.filter(
|
|
468
|
+
* ... pl.col("foo").lt(3)
|
|
469
|
+
* ... .and(pl.col("ham").eq(pl.lit("a")))
|
|
470
|
+
* ... )
|
|
471
|
+
* shape: (1, 3)
|
|
472
|
+
* ┌─────┬─────┬─────┐
|
|
473
|
+
* │ foo ┆ bar ┆ ham │
|
|
474
|
+
* │ --- ┆ --- ┆ --- │
|
|
475
|
+
* │ i64 ┆ i64 ┆ str │
|
|
476
|
+
* ╞═════╪═════╪═════╡
|
|
477
|
+
* │ 1 ┆ 6 ┆ a │
|
|
478
|
+
* └─────┴─────┴─────┘
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
filter(predicate: any): DataFrame<S>;
|
|
482
|
+
/**
|
|
483
|
+
* Find the index of a column by name.
|
|
484
|
+
* ___
|
|
485
|
+
* @param name -Name of the column to find.
|
|
486
|
+
* @example
|
|
487
|
+
* ```
|
|
488
|
+
* > const df = pl.DataFrame({
|
|
489
|
+
* ... "foo": [1, 2, 3],
|
|
490
|
+
* ... "bar": [6, 7, 8],
|
|
491
|
+
* ... "ham": ['a', 'b', 'c']
|
|
492
|
+
* ... });
|
|
493
|
+
* > df.findIdxByName("ham"))
|
|
494
|
+
* 2
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
findIdxByName(name: keyof S): number;
|
|
498
|
+
/**
|
|
499
|
+
* __Apply a horizontal reduction on a DataFrame.__
|
|
500
|
+
*
|
|
501
|
+
* This can be used to effectively determine aggregations on a row level,
|
|
502
|
+
* and can be applied to any DataType that can be supercasted (casted to a similar parent type).
|
|
503
|
+
*
|
|
504
|
+
* An example of the supercast rules when applying an arithmetic operation on two DataTypes are for instance:
|
|
505
|
+
* - Int8 + Utf8 = Utf8
|
|
506
|
+
* - Float32 + Int64 = Float32
|
|
507
|
+
* - Float32 + Float64 = Float64
|
|
508
|
+
* ___
|
|
509
|
+
* @param operation - function that takes two `Series` and returns a `Series`.
|
|
510
|
+
* @returns Series
|
|
511
|
+
* @example
|
|
512
|
+
* ```
|
|
513
|
+
* > // A horizontal sum operation
|
|
514
|
+
* > let df = pl.DataFrame({
|
|
515
|
+
* ... "a": [2, 1, 3],
|
|
516
|
+
* ... "b": [1, 2, 3],
|
|
517
|
+
* ... "c": [1.0, 2.0, 3.0]
|
|
518
|
+
* ... });
|
|
519
|
+
* > df.fold((s1, s2) => s1.plus(s2))
|
|
520
|
+
* Series: 'a' [f64]
|
|
521
|
+
* [
|
|
522
|
+
* 4
|
|
523
|
+
* 5
|
|
524
|
+
* 9
|
|
525
|
+
* ]
|
|
526
|
+
* > // A horizontal minimum operation
|
|
527
|
+
* > df = pl.DataFrame({
|
|
528
|
+
* ... "a": [2, 1, 3],
|
|
529
|
+
* ... "b": [1, 2, 3],
|
|
530
|
+
* ... "c": [1.0, 2.0, 3.0]
|
|
531
|
+
* ... });
|
|
532
|
+
* > df.fold((s1, s2) => s1.zipWith(s1.lt(s2), s2))
|
|
533
|
+
* Series: 'a' [f64]
|
|
534
|
+
* [
|
|
535
|
+
* 1
|
|
536
|
+
* 1
|
|
537
|
+
* 3
|
|
538
|
+
* ]
|
|
539
|
+
* > // A horizontal string concatenation
|
|
540
|
+
* > df = pl.DataFrame({
|
|
541
|
+
* ... "a": ["foo", "bar", 2],
|
|
542
|
+
* ... "b": [1, 2, 3],
|
|
543
|
+
* ... "c": [1.0, 2.0, 3.0]
|
|
544
|
+
* ... })
|
|
545
|
+
* > df.fold((s1, s2) => s.plus(s2))
|
|
546
|
+
* Series: '' [f64]
|
|
547
|
+
* [
|
|
548
|
+
* "foo11"
|
|
549
|
+
* "bar22
|
|
550
|
+
* "233"
|
|
551
|
+
* ]
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
fold<D extends DataType, F extends (s1: SchemaToSeriesRecord<S>[keyof S] | Series<D>, s2: SchemaToSeriesRecord<S>[keyof S]) => Series<D>>(operation: F): Series<D>;
|
|
555
|
+
/**
|
|
556
|
+
* Check if DataFrame is equal to other.
|
|
557
|
+
* ___
|
|
558
|
+
* @param other DataFrame to compare.
|
|
559
|
+
* @param nullEqual Consider null values as equal.
|
|
560
|
+
* @example
|
|
561
|
+
* ```
|
|
562
|
+
* > const df1 = pl.DataFrame({
|
|
563
|
+
* ... "foo": [1, 2, 3],
|
|
564
|
+
* ... "bar": [6.0, 7.0, 8.0],
|
|
565
|
+
* ... "ham": ['a', 'b', 'c']
|
|
566
|
+
* ... })
|
|
567
|
+
* > const df2 = pl.DataFrame({
|
|
568
|
+
* ... "foo": [3, 2, 1],
|
|
569
|
+
* ... "bar": [8.0, 7.0, 6.0],
|
|
570
|
+
* ... "ham": ['c', 'b', 'a']
|
|
571
|
+
* ... })
|
|
572
|
+
* > df1.frameEqual(df1)
|
|
573
|
+
* true
|
|
574
|
+
* > df1.frameEqual(df2)
|
|
575
|
+
* false
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
frameEqual(other: DataFrame, nullEqual: boolean): boolean;
|
|
579
|
+
frameEqual(other: DataFrame): boolean;
|
|
580
|
+
/**
|
|
581
|
+
* Get a single column as Series by name.
|
|
582
|
+
*
|
|
583
|
+
* ---
|
|
584
|
+
* @example
|
|
585
|
+
* ```
|
|
586
|
+
* > const df = pl.DataFrame({
|
|
587
|
+
* ... foo: [1, 2, 3],
|
|
588
|
+
* ... bar: [6, null, 8],
|
|
589
|
+
* ... ham: ["a", "b", "c"],
|
|
590
|
+
* ... });
|
|
591
|
+
* // df: pl.DataFrame<{
|
|
592
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
593
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
594
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
595
|
+
* // }>
|
|
596
|
+
* > const column = df.getColumn("foo");
|
|
597
|
+
* // column: pl.Series<Float64, "foo">
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
getColumn<U extends keyof S>(name: U): SchemaToSeriesRecord<S>[U];
|
|
601
|
+
getColumn(name: string): Series;
|
|
602
|
+
/**
|
|
603
|
+
* Get the DataFrame as an Array of Series.
|
|
604
|
+
* ---
|
|
605
|
+
* @example
|
|
606
|
+
* ```
|
|
607
|
+
* > const df = pl.DataFrame({
|
|
608
|
+
* ... foo: [1, 2, 3],
|
|
609
|
+
* ... bar: [6, null, 8],
|
|
610
|
+
* ... ham: ["a", "b", "c"],
|
|
611
|
+
* ... });
|
|
612
|
+
* // df: pl.DataFrame<{
|
|
613
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
614
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
615
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
616
|
+
* // }>
|
|
617
|
+
* > const columns = df.getColumns();
|
|
618
|
+
* // columns: (pl.Series<Float64, "foo"> | pl.Series<Float64, "bar"> | pl.Series<Utf8, "ham">)[]
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
getColumns(): SchemaToSeriesRecord<S>[keyof S][];
|
|
622
|
+
/**
|
|
623
|
+
* Start a groupby operation.
|
|
624
|
+
* ___
|
|
625
|
+
* @param by - Column(s) to group by.
|
|
626
|
+
*/
|
|
627
|
+
groupBy(...by: ColumnSelection[]): GroupBy;
|
|
628
|
+
/**
|
|
629
|
+
* Hash and combine the rows in this DataFrame. _(Hash value is UInt64)_
|
|
630
|
+
* @param k0 - seed parameter
|
|
631
|
+
* @param k1 - seed parameter
|
|
632
|
+
* @param k2 - seed parameter
|
|
633
|
+
* @param k3 - seed parameter
|
|
634
|
+
*/
|
|
635
|
+
hashRows(k0?: number, k1?: number, k2?: number, k3?: number): Series;
|
|
636
|
+
hashRows(options: {
|
|
637
|
+
k0?: number;
|
|
638
|
+
k1?: number;
|
|
639
|
+
k2?: number;
|
|
640
|
+
k3?: number;
|
|
641
|
+
}): Series;
|
|
642
|
+
/**
|
|
643
|
+
* Get first N rows as DataFrame.
|
|
644
|
+
* ___
|
|
645
|
+
* @param length - Length of the head.
|
|
646
|
+
* @example
|
|
647
|
+
* ```
|
|
648
|
+
* > const df = pl.DataFrame({
|
|
649
|
+
* ... "foo": [1, 2, 3, 4, 5],
|
|
650
|
+
* ... "bar": [6, 7, 8, 9, 10],
|
|
651
|
+
* ... "ham": ['a', 'b', 'c', 'd','e']
|
|
652
|
+
* ... });
|
|
653
|
+
* > df.head(3)
|
|
654
|
+
* shape: (3, 3)
|
|
655
|
+
* ╭─────┬─────┬─────╮
|
|
656
|
+
* │ foo ┆ bar ┆ ham │
|
|
657
|
+
* │ --- ┆ --- ┆ --- │
|
|
658
|
+
* │ i64 ┆ i64 ┆ str │
|
|
659
|
+
* ╞═════╪═════╪═════╡
|
|
660
|
+
* │ 1 ┆ 6 ┆ "a" │
|
|
661
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
662
|
+
* │ 2 ┆ 7 ┆ "b" │
|
|
663
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
664
|
+
* │ 3 ┆ 8 ┆ "c" │
|
|
665
|
+
* ╰─────┴─────┴─────╯
|
|
666
|
+
* ```
|
|
667
|
+
*/
|
|
668
|
+
head(length?: number): DataFrame<S>;
|
|
669
|
+
/**
|
|
670
|
+
* Return a new DataFrame grown horizontally by stacking multiple Series to it.
|
|
671
|
+
* @param columns - array of Series or DataFrame to stack
|
|
672
|
+
* @param inPlace - Modify in place
|
|
673
|
+
* @example
|
|
674
|
+
* ```
|
|
675
|
+
* > const df = pl.DataFrame({
|
|
676
|
+
* ... "foo": [1, 2, 3],
|
|
677
|
+
* ... "bar": [6, 7, 8],
|
|
678
|
+
* ... "ham": ['a', 'b', 'c']
|
|
679
|
+
* ... });
|
|
680
|
+
* // df: pl.DataFrame<{
|
|
681
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
682
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
683
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
684
|
+
* // }>
|
|
685
|
+
* > const x = pl.Series("apple", [10, 20, 30])
|
|
686
|
+
* // x: pl.Series<Float64, "apple">
|
|
687
|
+
* > df.hstack([x])
|
|
688
|
+
* // pl.DataFrame<{
|
|
689
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
690
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
691
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
692
|
+
* // apple: pl.Series<Float64, "apple">;
|
|
693
|
+
* // }>
|
|
694
|
+
* shape: (3, 4)
|
|
695
|
+
* ╭─────┬─────┬─────┬───────╮
|
|
696
|
+
* │ foo ┆ bar ┆ ham ┆ apple │
|
|
697
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
698
|
+
* │ i64 ┆ i64 ┆ str ┆ i64 │
|
|
699
|
+
* ╞═════╪═════╪═════╪═══════╡
|
|
700
|
+
* │ 1 ┆ 6 ┆ "a" ┆ 10 │
|
|
701
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
|
702
|
+
* │ 2 ┆ 7 ┆ "b" ┆ 20 │
|
|
703
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
|
704
|
+
* │ 3 ┆ 8 ┆ "c" ┆ 30 │
|
|
705
|
+
* ╰─────┴─────┴─────┴───────╯
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
hstack(columns: Array<Series> | DataFrame, inPlace?: boolean): void;
|
|
709
|
+
hstack<S2 extends Schema = Schema>(columns: DataFrame<S2>): DataFrame<Simplify<S & S2>>;
|
|
710
|
+
hstack<U extends Series[]>(columns: U): DataFrame<Simplify<S & {
|
|
711
|
+
[K in U[number] as K["name"]]: K;
|
|
712
|
+
}>>;
|
|
713
|
+
hstack(columns: Array<Series> | DataFrame, inPlace?: boolean): void;
|
|
714
|
+
/**
|
|
715
|
+
* Insert a Series at a certain column index. This operation is in place.
|
|
716
|
+
* @param index - Column position to insert the new `Series` column.
|
|
717
|
+
* @param series - `Series` to insert
|
|
718
|
+
*/
|
|
719
|
+
insertAtIdx(index: number, series: Series): void;
|
|
720
|
+
/**
|
|
721
|
+
* Interpolate intermediate values. The interpolation method is linear.
|
|
722
|
+
*/
|
|
723
|
+
interpolate(): DataFrame<S>;
|
|
724
|
+
/**
|
|
725
|
+
* Get a mask of all duplicated rows in this DataFrame.
|
|
726
|
+
*/
|
|
727
|
+
isDuplicated(): Series;
|
|
728
|
+
/**
|
|
729
|
+
* Check if the dataframe is empty
|
|
730
|
+
*/
|
|
731
|
+
isEmpty(): boolean;
|
|
732
|
+
/**
|
|
733
|
+
* Get a mask of all unique rows in this DataFrame.
|
|
734
|
+
*/
|
|
735
|
+
isUnique(): Series;
|
|
736
|
+
/**
|
|
737
|
+
* __SQL like joins.__
|
|
738
|
+
* @param other - DataFrame to join with.
|
|
739
|
+
* @param options
|
|
740
|
+
* @param options.on - Name(s) of the join columns in both DataFrames.
|
|
741
|
+
* @param options.how - Join strategy
|
|
742
|
+
* @param options.suffix - Suffix to append to columns with a duplicate name.
|
|
743
|
+
* @param options.coalesce - Coalescing behavior (merging of join columns).
|
|
744
|
+
* @see {@link SameNameColumnJoinOptions}
|
|
745
|
+
* @example
|
|
746
|
+
* ```
|
|
747
|
+
* > const df = pl.DataFrame({
|
|
748
|
+
* ... "foo": [1, 2, 3],
|
|
749
|
+
* ... "bar": [6.0, 7.0, 8.0],
|
|
750
|
+
* ... "ham": ['a', 'b', 'c']
|
|
751
|
+
* ... });
|
|
752
|
+
* > const otherDF = pl.DataFrame({
|
|
753
|
+
* ... "apple": ['x', 'y', 'z'],
|
|
754
|
+
* ... "ham": ['a', 'b', 'd']
|
|
755
|
+
* ... });
|
|
756
|
+
* > df.join(otherDF, {on: 'ham'})
|
|
757
|
+
* shape: (2, 4)
|
|
758
|
+
* ╭─────┬─────┬─────┬───────╮
|
|
759
|
+
* │ foo ┆ bar ┆ ham ┆ apple │
|
|
760
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
761
|
+
* │ i64 ┆ f64 ┆ str ┆ str │
|
|
762
|
+
* ╞═════╪═════╪═════╪═══════╡
|
|
763
|
+
* │ 1 ┆ 6 ┆ "a" ┆ "x" │
|
|
764
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
|
765
|
+
* │ 2 ┆ 7 ┆ "b" ┆ "y" │
|
|
766
|
+
* ╰─────┴─────┴─────┴───────╯
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
join<S2 extends Schema, const Opts extends SameNameColumnJoinOptions<Extract<keyof S, string>, Extract<keyof S2, string>>>(other: DataFrame<S2>, options: Opts & SameNameColumnJoinOptions): DataFrame<JoinSchemas<S, S2, Opts>>;
|
|
770
|
+
/**
|
|
771
|
+
* __SQL like joins with different names for left and right dataframes.__
|
|
772
|
+
* @param other - DataFrame to join with.
|
|
773
|
+
* @param options
|
|
774
|
+
* @param options.leftOn - Name(s) of the left join column(s).
|
|
775
|
+
* @param options.rightOn - Name(s) of the right join column(s).
|
|
776
|
+
* @param options.how - Join strategy
|
|
777
|
+
* @param options.suffix - Suffix to append to columns with a duplicate name.
|
|
778
|
+
* @param options.coalesce - Coalescing behavior (merging of join columns).
|
|
779
|
+
* @see {@link DifferentNameColumnJoinOptions}
|
|
780
|
+
* @example
|
|
781
|
+
* ```
|
|
782
|
+
* > const df = pl.DataFrame({
|
|
783
|
+
* ... "foo": [1, 2, 3],
|
|
784
|
+
* ... "bar": [6.0, 7.0, 8.0],
|
|
785
|
+
* ... "ham": ['a', 'b', 'c']
|
|
786
|
+
* ... });
|
|
787
|
+
* > const otherDF = pl.DataFrame({
|
|
788
|
+
* ... "apple": ['x', 'y', 'z'],
|
|
789
|
+
* ... "ham": ['a', 'b', 'd']
|
|
790
|
+
* ... });
|
|
791
|
+
* > df.join(otherDF, {leftOn: 'ham', rightOn: 'ham'})
|
|
792
|
+
* shape: (2, 4)
|
|
793
|
+
* ╭─────┬─────┬─────┬───────╮
|
|
794
|
+
* │ foo ┆ bar ┆ ham ┆ apple │
|
|
795
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
796
|
+
* │ i64 ┆ f64 ┆ str ┆ str │
|
|
797
|
+
* ╞═════╪═════╪═════╪═══════╡
|
|
798
|
+
* │ 1 ┆ 6 ┆ "a" ┆ "x" │
|
|
799
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
|
800
|
+
* │ 2 ┆ 7 ┆ "b" ┆ "y" │
|
|
801
|
+
* ╰─────┴─────┴─────┴───────╯
|
|
802
|
+
* ```
|
|
803
|
+
*/
|
|
804
|
+
join<S2 extends Schema, const Opts extends DifferentNameColumnJoinOptions<Extract<keyof S, string>, Extract<keyof S2, string>>>(other: DataFrame<S2>, options: Opts & DifferentNameColumnJoinOptions): DataFrame<JoinSchemas<S, S2, Opts>>;
|
|
805
|
+
/**
|
|
806
|
+
* __SQL like cross joins.__
|
|
807
|
+
* @param other - DataFrame to join with.
|
|
808
|
+
* @param options
|
|
809
|
+
* @param options.how - Join strategy
|
|
810
|
+
* @param options.suffix - Suffix to append to columns with a duplicate name.
|
|
811
|
+
* @param options.coalesce - Coalescing behavior (merging of join columns).
|
|
812
|
+
* @see {@link CrossJoinOptions}
|
|
813
|
+
* @example
|
|
814
|
+
* ```
|
|
815
|
+
* > const df = pl.DataFrame({
|
|
816
|
+
* ... "foo": [1, 2],
|
|
817
|
+
* ... "bar": [6.0, 7.0],
|
|
818
|
+
* ... "ham": ['a', 'b']
|
|
819
|
+
* ... });
|
|
820
|
+
* > const otherDF = pl.DataFrame({
|
|
821
|
+
* ... "apple": ['x', 'y'],
|
|
822
|
+
* ... "ham": ['a', 'b']
|
|
823
|
+
* ... });
|
|
824
|
+
* > df.join(otherDF, {how: 'cross'})
|
|
825
|
+
* shape: (4, 5)
|
|
826
|
+
* ╭─────┬─────┬─────┬───────┬───────────╮
|
|
827
|
+
* │ foo ┆ bar ┆ ham ┆ apple ┆ ham_right │
|
|
828
|
+
* │ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
|
829
|
+
* │ f64 ┆ f64 ┆ str ┆ str ┆ str │
|
|
830
|
+
* ╞═════╪═════╪═════╪═══════╪═══════════╡
|
|
831
|
+
* │ 1.0 ┆ 6.0 ┆ a ┆ x ┆ a │
|
|
832
|
+
* │ 1.0 ┆ 6.0 ┆ a ┆ y ┆ b │
|
|
833
|
+
* │ 2.0 ┆ 7.0 ┆ b ┆ x ┆ a │
|
|
834
|
+
* │ 2.0 ┆ 7.0 ┆ b ┆ y ┆ b │
|
|
835
|
+
* ╰─────┴─────┴─────┴───────┴───────────╯
|
|
836
|
+
* ```
|
|
837
|
+
*/
|
|
838
|
+
join<S2 extends Schema, const Opts extends CrossJoinOptions>(other: DataFrame<S2>, options: Opts & CrossJoinOptions): DataFrame<JoinSchemas<S, S2, Opts>>;
|
|
839
|
+
/**
|
|
840
|
+
* Perform an asof join. This is similar to a left-join except that we
|
|
841
|
+
* match on nearest key rather than equal keys.
|
|
842
|
+
*
|
|
843
|
+
* Both DataFrames must be sorted by the asofJoin key.
|
|
844
|
+
*
|
|
845
|
+
* For each row in the left DataFrame:
|
|
846
|
+
* - A "backward" search selects the last row in the right DataFrame whose
|
|
847
|
+
* 'on' key is less than or equal to the left's key.
|
|
848
|
+
*
|
|
849
|
+
* - A "forward" search selects the first row in the right DataFrame whose
|
|
850
|
+
* 'on' key is greater than or equal to the left's key.
|
|
851
|
+
*
|
|
852
|
+
* - A "nearest" search selects the last row in the right DataFrame whose value
|
|
853
|
+
* is nearest to the left's key. String keys are not currently supported for a
|
|
854
|
+
* nearest search.
|
|
855
|
+
*
|
|
856
|
+
* The default is "backward".
|
|
857
|
+
*
|
|
858
|
+
* @param other DataFrame to join with.
|
|
859
|
+
* @param options.leftOn Join column of the left DataFrame.
|
|
860
|
+
* @param options.rightOn Join column of the right DataFrame.
|
|
861
|
+
* @param options.on Join column of both DataFrames. If set, `leftOn` and `rightOn` should be undefined.
|
|
862
|
+
* @param options.byLeft join on these columns before doing asof join
|
|
863
|
+
* @param options.byRight join on these columns before doing asof join
|
|
864
|
+
* @param options.strategy One of 'forward', 'backward', 'nearest'
|
|
865
|
+
* @param options.suffix Suffix to append to columns with a duplicate name.
|
|
866
|
+
* @param options.tolerance
|
|
867
|
+
* Numeric tolerance. By setting this the join will only be done if the near keys are within this distance.
|
|
868
|
+
* If an asof join is done on columns of dtype "Date", "Datetime" you
|
|
869
|
+
* use the following string language:
|
|
870
|
+
*
|
|
871
|
+
* - 1ns *(1 nanosecond)*
|
|
872
|
+
* - 1us *(1 microsecond)*
|
|
873
|
+
* - 1ms *(1 millisecond)*
|
|
874
|
+
* - 1s *(1 second)*
|
|
875
|
+
* - 1m *(1 minute)*
|
|
876
|
+
* - 1h *(1 hour)*
|
|
877
|
+
* - 1d *(1 day)*
|
|
878
|
+
* - 1w *(1 week)*
|
|
879
|
+
* - 1mo *(1 calendar month)*
|
|
880
|
+
* - 1y *(1 calendar year)*
|
|
881
|
+
* - 1i *(1 index count)*
|
|
882
|
+
*
|
|
883
|
+
* Or combine them:
|
|
884
|
+
* - "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
|
|
885
|
+
* @param options.allowParallel Allow the physical plan to optionally evaluate the computation of both DataFrames up to the join in parallel.
|
|
886
|
+
* @param options.forceParallel Force the physical plan to evaluate the computation of both DataFrames up to the join in parallel.
|
|
887
|
+
* @param options.checkSortedness
|
|
888
|
+
* Check the sortedness of the asof keys. If the keys are not sorted Polars
|
|
889
|
+
* will error, or in case of 'by' argument raise a warning. This might become
|
|
890
|
+
* a hard error in the future.
|
|
891
|
+
*
|
|
892
|
+
* @example
|
|
893
|
+
* ```
|
|
894
|
+
* > const gdp = pl.DataFrame({
|
|
895
|
+
* ... date: [
|
|
896
|
+
* ... new Date('2016-01-01'),
|
|
897
|
+
* ... new Date('2017-01-01'),
|
|
898
|
+
* ... new Date('2018-01-01'),
|
|
899
|
+
* ... new Date('2019-01-01'),
|
|
900
|
+
* ... ], // note record date: Jan 1st (sorted!)
|
|
901
|
+
* ... gdp: [4164, 4411, 4566, 4696],
|
|
902
|
+
* ... })
|
|
903
|
+
* > const population = pl.DataFrame({
|
|
904
|
+
* ... date: [
|
|
905
|
+
* ... new Date('2016-05-12'),
|
|
906
|
+
* ... new Date('2017-05-12'),
|
|
907
|
+
* ... new Date('2018-05-12'),
|
|
908
|
+
* ... new Date('2019-05-12'),
|
|
909
|
+
* ... ], // note record date: May 12th (sorted!)
|
|
910
|
+
* ... "population": [82.19, 82.66, 83.12, 83.52],
|
|
911
|
+
* ... })
|
|
912
|
+
* > population.joinAsof(
|
|
913
|
+
* ... gdp,
|
|
914
|
+
* ... {leftOn:"date", rightOn:"date", strategy:"backward"}
|
|
915
|
+
* ... )
|
|
916
|
+
* shape: (4, 3)
|
|
917
|
+
* ┌─────────────────────┬────────────┬──────┐
|
|
918
|
+
* │ date ┆ population ┆ gdp │
|
|
919
|
+
* │ --- ┆ --- ┆ --- │
|
|
920
|
+
* │ datetime[μs] ┆ f64 ┆ i64 │
|
|
921
|
+
* ╞═════════════════════╪════════════╪══════╡
|
|
922
|
+
* │ 2016-05-12 00:00:00 ┆ 82.19 ┆ 4164 │
|
|
923
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
924
|
+
* │ 2017-05-12 00:00:00 ┆ 82.66 ┆ 4411 │
|
|
925
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
926
|
+
* │ 2018-05-12 00:00:00 ┆ 83.12 ┆ 4566 │
|
|
927
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
928
|
+
* │ 2019-05-12 00:00:00 ┆ 83.52 ┆ 4696 │
|
|
929
|
+
* └─────────────────────┴────────────┴──────┘
|
|
930
|
+
* ```
|
|
931
|
+
*/
|
|
932
|
+
joinAsof(other: DataFrame, options: {
|
|
933
|
+
leftOn?: string;
|
|
934
|
+
rightOn?: string;
|
|
935
|
+
on?: string;
|
|
936
|
+
byLeft?: string | string[];
|
|
937
|
+
byRight?: string | string[];
|
|
938
|
+
by?: string | string[];
|
|
939
|
+
strategy?: "backward" | "forward" | "nearest";
|
|
940
|
+
suffix?: string;
|
|
941
|
+
tolerance?: number | string;
|
|
942
|
+
allowParallel?: boolean;
|
|
943
|
+
forceParallel?: boolean;
|
|
944
|
+
checkSortedness?: boolean;
|
|
945
|
+
}): DataFrame;
|
|
946
|
+
lazy(): LazyDataFrame<S>;
|
|
947
|
+
/**
|
|
948
|
+
* Get first N rows as DataFrame.
|
|
949
|
+
* @see {@link head}
|
|
950
|
+
*/
|
|
951
|
+
limit(length?: number): DataFrame<S>;
|
|
952
|
+
map<ReturnT>(func: (row: any[], i: number, arr: any[][]) => ReturnT): ReturnT[];
|
|
953
|
+
/**
|
|
954
|
+
* Aggregate the columns of this DataFrame to their maximum value.
|
|
955
|
+
* ___
|
|
956
|
+
* @param axis - either 0 or 1
|
|
957
|
+
* @example
|
|
958
|
+
* ```
|
|
959
|
+
* > const df = pl.DataFrame({
|
|
960
|
+
* ... "foo": [1, 2, 3],
|
|
961
|
+
* ... "bar": [6, 7, 8],
|
|
962
|
+
* ... "ham": ['a', 'b', 'c']
|
|
963
|
+
* ... });
|
|
964
|
+
* > df.max()
|
|
965
|
+
* shape: (1, 3)
|
|
966
|
+
* ╭─────┬─────┬──────╮
|
|
967
|
+
* │ foo ┆ bar ┆ ham │
|
|
968
|
+
* │ --- ┆ --- ┆ --- │
|
|
969
|
+
* │ i64 ┆ i64 ┆ str │
|
|
970
|
+
* ╞═════╪═════╪══════╡
|
|
971
|
+
* │ 3 ┆ 8 ┆ null │
|
|
972
|
+
* ╰─────┴─────┴──────╯
|
|
973
|
+
* ```
|
|
974
|
+
*/
|
|
975
|
+
max(axis: 0): DataFrame<S>;
|
|
976
|
+
max(axis: 1): Series;
|
|
977
|
+
max(): DataFrame<S>;
|
|
978
|
+
/**
|
|
979
|
+
* Aggregate the columns of this DataFrame to their mean value.
|
|
980
|
+
* ___
|
|
981
|
+
*
|
|
982
|
+
* @param axis - either 0 or 1
|
|
983
|
+
* @param nullStrategy - this argument is only used if axis == 1
|
|
984
|
+
*/
|
|
985
|
+
mean(axis: 1, nullStrategy?: "ignore" | "propagate"): Series;
|
|
986
|
+
mean(): DataFrame<S>;
|
|
987
|
+
mean(axis: 0): DataFrame<S>;
|
|
988
|
+
mean(axis: 1): Series;
|
|
989
|
+
/**
|
|
990
|
+
* Aggregate the columns of this DataFrame to their median value.
|
|
991
|
+
* ___
|
|
992
|
+
* @example
|
|
993
|
+
* ```
|
|
994
|
+
* > const df = pl.DataFrame({
|
|
995
|
+
* ... "foo": [1, 2, 3],
|
|
996
|
+
* ... "bar": [6, 7, 8],
|
|
997
|
+
* ... "ham": ['a', 'b', 'c']
|
|
998
|
+
* ... });
|
|
999
|
+
* > df.median();
|
|
1000
|
+
* shape: (1, 3)
|
|
1001
|
+
* ╭─────┬─────┬──────╮
|
|
1002
|
+
* │ foo ┆ bar ┆ ham │
|
|
1003
|
+
* │ --- ┆ --- ┆ --- │
|
|
1004
|
+
* │ f64 ┆ f64 ┆ str │
|
|
1005
|
+
* ╞═════╪═════╪══════╡
|
|
1006
|
+
* │ 2 ┆ 7 ┆ null │
|
|
1007
|
+
* ╰─────┴─────┴──────╯
|
|
1008
|
+
* ```
|
|
1009
|
+
*/
|
|
1010
|
+
median(): DataFrame<S>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Unpivot a DataFrame from wide to long format.
|
|
1013
|
+
* ___
|
|
1014
|
+
*
|
|
1015
|
+
* @param idVars - Columns to use as identifier variables.
|
|
1016
|
+
* @param valueVars - Values to use as value variables.
|
|
1017
|
+
* @param options.variableName - Name to give to the `variable` column. Defaults to "variable"
|
|
1018
|
+
* @param options.valueName - Name to give to the `value` column. Defaults to "value"
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```
|
|
1021
|
+
* > const df1 = pl.DataFrame({
|
|
1022
|
+
* ... 'id': [1],
|
|
1023
|
+
* ... 'asset_key_1': ['123'],
|
|
1024
|
+
* ... 'asset_key_2': ['456'],
|
|
1025
|
+
* ... 'asset_key_3': ['abc'],
|
|
1026
|
+
* ... });
|
|
1027
|
+
* > df1.unpivot('id', ['asset_key_1', 'asset_key_2', 'asset_key_3']);
|
|
1028
|
+
* shape: (3, 3)
|
|
1029
|
+
* ┌─────┬─────────────┬───────┐
|
|
1030
|
+
* │ id ┆ variable ┆ value │
|
|
1031
|
+
* │ --- ┆ --- ┆ --- │
|
|
1032
|
+
* │ f64 ┆ str ┆ str │
|
|
1033
|
+
* ╞═════╪═════════════╪═══════╡
|
|
1034
|
+
* │ 1 ┆ asset_key_1 ┆ 123 │
|
|
1035
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
|
1036
|
+
* │ 1 ┆ asset_key_2 ┆ 456 │
|
|
1037
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
|
1038
|
+
* │ 1 ┆ asset_key_3 ┆ abc │
|
|
1039
|
+
* └─────┴─────────────┴───────┘
|
|
1040
|
+
* ```
|
|
1041
|
+
*/
|
|
1042
|
+
unpivot(idVars: ColumnSelection, valueVars: ColumnSelection, options?: {
|
|
1043
|
+
variableName?: string | null;
|
|
1044
|
+
valueName?: string | null;
|
|
1045
|
+
}): DataFrame;
|
|
1046
|
+
/**
|
|
1047
|
+
* Aggregate the columns of this DataFrame to their minimum value.
|
|
1048
|
+
* ___
|
|
1049
|
+
* @param axis - either 0 or 1
|
|
1050
|
+
* @example
|
|
1051
|
+
* ```
|
|
1052
|
+
* > const df = pl.DataFrame({
|
|
1053
|
+
* ... "foo": [1, 2, 3],
|
|
1054
|
+
* ... "bar": [6, 7, 8],
|
|
1055
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1056
|
+
* ... });
|
|
1057
|
+
* > df.min();
|
|
1058
|
+
* shape: (1, 3)
|
|
1059
|
+
* ╭─────┬─────┬──────╮
|
|
1060
|
+
* │ foo ┆ bar ┆ ham │
|
|
1061
|
+
* │ --- ┆ --- ┆ --- │
|
|
1062
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1063
|
+
* ╞═════╪═════╪══════╡
|
|
1064
|
+
* │ 1 ┆ 6 ┆ null │
|
|
1065
|
+
* ╰─────┴─────┴──────╯
|
|
1066
|
+
* ```
|
|
1067
|
+
*/
|
|
1068
|
+
min(axis: 0): DataFrame<S>;
|
|
1069
|
+
min(axis: 1): Series;
|
|
1070
|
+
min(): DataFrame<S>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Get number of chunks used by the ChunkedArrays of this DataFrame.
|
|
1073
|
+
*/
|
|
1074
|
+
nChunks(): number;
|
|
1075
|
+
/**
|
|
1076
|
+
* Create a new DataFrame that shows the null counts per column.
|
|
1077
|
+
* ___
|
|
1078
|
+
* @example
|
|
1079
|
+
* ```
|
|
1080
|
+
* > const df = pl.DataFrame({
|
|
1081
|
+
* ... "foo": [1, null, 3],
|
|
1082
|
+
* ... "bar": [6, 7, null],
|
|
1083
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1084
|
+
* ... });
|
|
1085
|
+
* > df.nullCount();
|
|
1086
|
+
* shape: (1, 3)
|
|
1087
|
+
* ┌─────┬─────┬─────┐
|
|
1088
|
+
* │ foo ┆ bar ┆ ham │
|
|
1089
|
+
* │ --- ┆ --- ┆ --- │
|
|
1090
|
+
* │ u32 ┆ u32 ┆ u32 │
|
|
1091
|
+
* ╞═════╪═════╪═════╡
|
|
1092
|
+
* │ 1 ┆ 1 ┆ 0 │
|
|
1093
|
+
* └─────┴─────┴─────┘
|
|
1094
|
+
* ```
|
|
1095
|
+
*/
|
|
1096
|
+
nullCount(): DataFrame<{
|
|
1097
|
+
[K in keyof S]: JsToDtype<number>;
|
|
1098
|
+
}>;
|
|
1099
|
+
partitionBy(cols: string | string[], stable?: boolean, includeKey?: boolean): DataFrame<S>[];
|
|
1100
|
+
partitionBy<T>(cols: string | string[], stable: boolean, includeKey: boolean, mapFn: (df: DataFrame) => T): T[];
|
|
1101
|
+
/**
|
|
1102
|
+
* Create a spreadsheet-style pivot table as a DataFrame.
|
|
1103
|
+
*
|
|
1104
|
+
* @param values The existing column(s) of values which will be moved under the new columns from index. If an
|
|
1105
|
+
* aggregation is specified, these are the values on which the aggregation will be computed.
|
|
1106
|
+
* If None, all remaining columns not specified on `on` and `index` will be used.
|
|
1107
|
+
* At least one of `index` and `values` must be specified.
|
|
1108
|
+
* @param options.index The column(s) that remain from the input to the output. The output DataFrame will have one row
|
|
1109
|
+
* for each unique combination of the `index`'s values.
|
|
1110
|
+
* If None, all remaining columns not specified on `on` and `values` will be used. At least one
|
|
1111
|
+
* of `index` and `values` must be specified.
|
|
1112
|
+
* @param options.on The column(s) whose values will be used as the new columns of the output DataFrame.
|
|
1113
|
+
* @param options.aggregateFunc
|
|
1114
|
+
* Any of:
|
|
1115
|
+
* - "sum"
|
|
1116
|
+
* - "max"
|
|
1117
|
+
* - "min"
|
|
1118
|
+
* - "mean"
|
|
1119
|
+
* - "median"
|
|
1120
|
+
* - "first"
|
|
1121
|
+
* - "last"
|
|
1122
|
+
* - "count"
|
|
1123
|
+
* Defaults to "first"
|
|
1124
|
+
* @param options.maintainOrder Sort the grouped keys so that the output order is predictable.
|
|
1125
|
+
* @param options.sortColumns Sort the transposed columns by name. Default is by order of discovery.
|
|
1126
|
+
* @param options.separator Used as separator/delimiter in generated column names.
|
|
1127
|
+
* @example
|
|
1128
|
+
* ```
|
|
1129
|
+
* > const df = pl.DataFrame(
|
|
1130
|
+
* ... {
|
|
1131
|
+
* ... "foo": ["one", "one", "one", "two", "two", "two"],
|
|
1132
|
+
* ... "bar": ["A", "B", "C", "A", "B", "C"],
|
|
1133
|
+
* ... "baz": [1, 2, 3, 4, 5, 6],
|
|
1134
|
+
* ... }
|
|
1135
|
+
* ... );
|
|
1136
|
+
* > df.pivot("baz", {index:"foo", on:"bar"});
|
|
1137
|
+
* shape: (2, 4)
|
|
1138
|
+
* ┌─────┬─────┬─────┬─────┐
|
|
1139
|
+
* │ foo ┆ A ┆ B ┆ C │
|
|
1140
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
1141
|
+
* │ str ┆ f64 ┆ f64 ┆ f64 │
|
|
1142
|
+
* ╞═════╪═════╪═════╪═════╡
|
|
1143
|
+
* │ one ┆ 1 ┆ 2 ┆ 3 │
|
|
1144
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1145
|
+
* │ two ┆ 4 ┆ 5 ┆ 6 │
|
|
1146
|
+
* └─────┴─────┴─────┴─────┘
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
pivot(values: string | string[], options: {
|
|
1150
|
+
index: string | string[];
|
|
1151
|
+
on: string | string[];
|
|
1152
|
+
aggregateFunc?: "sum" | "max" | "min" | "mean" | "median" | "first" | "last" | "count" | Expr;
|
|
1153
|
+
maintainOrder?: boolean;
|
|
1154
|
+
sortColumns?: boolean;
|
|
1155
|
+
separator?: string;
|
|
1156
|
+
}): DataFrame;
|
|
1157
|
+
pivot(options: {
|
|
1158
|
+
values: string | string[];
|
|
1159
|
+
index: string | string[];
|
|
1160
|
+
on: string | string[];
|
|
1161
|
+
aggregateFunc?: "sum" | "max" | "min" | "mean" | "median" | "first" | "last" | "count" | Expr;
|
|
1162
|
+
maintainOrder?: boolean;
|
|
1163
|
+
sortColumns?: boolean;
|
|
1164
|
+
separator?: string;
|
|
1165
|
+
}): DataFrame;
|
|
1166
|
+
/**
|
|
1167
|
+
* Aggregate the columns of this DataFrame to their quantile value.
|
|
1168
|
+
* @example
|
|
1169
|
+
* ```
|
|
1170
|
+
* > const df = pl.DataFrame({
|
|
1171
|
+
* ... "foo": [1, 2, 3],
|
|
1172
|
+
* ... "bar": [6, 7, 8],
|
|
1173
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1174
|
+
* ... });
|
|
1175
|
+
* > df.quantile(0.5);
|
|
1176
|
+
* shape: (1, 3)
|
|
1177
|
+
* ╭─────┬─────┬──────╮
|
|
1178
|
+
* │ foo ┆ bar ┆ ham │
|
|
1179
|
+
* │ --- ┆ --- ┆ --- │
|
|
1180
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1181
|
+
* ╞═════╪═════╪══════╡
|
|
1182
|
+
* │ 2 ┆ 7 ┆ null │
|
|
1183
|
+
* ╰─────┴─────┴──────╯
|
|
1184
|
+
* ```
|
|
1185
|
+
*/
|
|
1186
|
+
quantile(quantile: number): DataFrame<S>;
|
|
1187
|
+
/**
|
|
1188
|
+
* __Rechunk the data in this DataFrame to a contiguous allocation.__
|
|
1189
|
+
*
|
|
1190
|
+
* This will make sure all subsequent operations have optimal and predictable performance.
|
|
1191
|
+
*/
|
|
1192
|
+
rechunk(): DataFrame<S>;
|
|
1193
|
+
/**
|
|
1194
|
+
* __Rename column names.__
|
|
1195
|
+
* ___
|
|
1196
|
+
*
|
|
1197
|
+
* @param mapping - Key value pairs that map from old name to new name.
|
|
1198
|
+
* @example
|
|
1199
|
+
* ```
|
|
1200
|
+
* > const df = pl.DataFrame({
|
|
1201
|
+
* ... "foo": [1, 2, 3],
|
|
1202
|
+
* ... "bar": [6, 7, 8],
|
|
1203
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1204
|
+
* ... });
|
|
1205
|
+
* // df: pl.DataFrame<{
|
|
1206
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
1207
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
1208
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
1209
|
+
* // }>
|
|
1210
|
+
* > df.rename({"foo": "apple"});
|
|
1211
|
+
* ╭───────┬─────┬─────╮
|
|
1212
|
+
* │ apple ┆ bar ┆ ham │
|
|
1213
|
+
* │ --- ┆ --- ┆ --- │
|
|
1214
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1215
|
+
* ╞═══════╪═════╪═════╡
|
|
1216
|
+
* │ 1 ┆ 6 ┆ "a" │
|
|
1217
|
+
* ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1218
|
+
* │ 2 ┆ 7 ┆ "b" │
|
|
1219
|
+
* ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1220
|
+
* │ 3 ┆ 8 ┆ "c" │
|
|
1221
|
+
* ╰───────┴─────┴─────╯
|
|
1222
|
+
* ```
|
|
1223
|
+
*/
|
|
1224
|
+
rename<const U extends Partial<Record<keyof S, string>>>(mapping: U): DataFrame<{
|
|
1225
|
+
[K in keyof S as U[K] extends string ? U[K] : K]: S[K];
|
|
1226
|
+
}>;
|
|
1227
|
+
rename(mapping: Record<string, string>): DataFrame;
|
|
1228
|
+
/**
|
|
1229
|
+
* Replace a column at an index location.
|
|
1230
|
+
*
|
|
1231
|
+
* Warning: typescript cannot encode type mutation,
|
|
1232
|
+
* so the type of the DataFrame will be incorrect. cast the type of dataframe manually.
|
|
1233
|
+
* ___
|
|
1234
|
+
* @param index - Column index
|
|
1235
|
+
* @param newColumn - New column to insert
|
|
1236
|
+
* @example
|
|
1237
|
+
* ```
|
|
1238
|
+
* > const df: pl.DataFrame = pl.DataFrame({
|
|
1239
|
+
* ... "foo": [1, 2, 3],
|
|
1240
|
+
* ... "bar": [6, 7, 8],
|
|
1241
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1242
|
+
* ... });
|
|
1243
|
+
* // df: pl.DataFrame<{
|
|
1244
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
1245
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
1246
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
1247
|
+
* // }>
|
|
1248
|
+
* > const x = pl.Series("apple", [10, 20, 30]);
|
|
1249
|
+
* // x: pl.Series<Float64, "apple">
|
|
1250
|
+
* > df.replaceAtIdx(0, x);
|
|
1251
|
+
* // df: pl.DataFrame<{
|
|
1252
|
+
* // foo: pl.Series<Float64, "foo">; <- notice how the type is still the same!
|
|
1253
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
1254
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
1255
|
+
* // }>
|
|
1256
|
+
* shape: (3, 3)
|
|
1257
|
+
* ╭───────┬─────┬─────╮
|
|
1258
|
+
* │ apple ┆ bar ┆ ham │
|
|
1259
|
+
* │ --- ┆ --- ┆ --- │
|
|
1260
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1261
|
+
* ╞═══════╪═════╪═════╡
|
|
1262
|
+
* │ 10 ┆ 6 ┆ "a" │
|
|
1263
|
+
* ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1264
|
+
* │ 20 ┆ 7 ┆ "b" │
|
|
1265
|
+
* ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1266
|
+
* │ 30 ┆ 8 ┆ "c" │
|
|
1267
|
+
* ╰───────┴─────┴─────╯
|
|
1268
|
+
* ```
|
|
1269
|
+
*/
|
|
1270
|
+
replaceAtIdx(index: number, newColumn: Series): void;
|
|
1271
|
+
/**
|
|
1272
|
+
* Get a row as Array
|
|
1273
|
+
* @param index - row index
|
|
1274
|
+
* @example
|
|
1275
|
+
* ```
|
|
1276
|
+
* > const df = pl.DataFrame({
|
|
1277
|
+
* ... "foo": [1, 2, 3],
|
|
1278
|
+
* ... "bar": [6, 7, 8],
|
|
1279
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1280
|
+
* ... });
|
|
1281
|
+
* > df.row(2)
|
|
1282
|
+
* [3, 8, 'c']
|
|
1283
|
+
* ```
|
|
1284
|
+
*/
|
|
1285
|
+
row(index: number): Array<any>;
|
|
1286
|
+
/**
|
|
1287
|
+
* Convert columnar data to rows as arrays
|
|
1288
|
+
*/
|
|
1289
|
+
rows(): Array<Array<any>>;
|
|
1290
|
+
/**
|
|
1291
|
+
* @example
|
|
1292
|
+
* ```
|
|
1293
|
+
* > const df: pl.DataFrame = pl.DataFrame({
|
|
1294
|
+
* ... "foo": [1, 2, 3],
|
|
1295
|
+
* ... "bar": [6, 7, 8],
|
|
1296
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1297
|
+
* ... });
|
|
1298
|
+
* // df: pl.DataFrame<{
|
|
1299
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
1300
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
1301
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
1302
|
+
* // }>
|
|
1303
|
+
* > df.schema
|
|
1304
|
+
* // {
|
|
1305
|
+
* // foo: Float64;
|
|
1306
|
+
* // bar: Float64;
|
|
1307
|
+
* // ham: Utf8;
|
|
1308
|
+
* // }
|
|
1309
|
+
* ```
|
|
1310
|
+
*/
|
|
1311
|
+
get schema(): S;
|
|
1312
|
+
/**
|
|
1313
|
+
* Select columns from this DataFrame.
|
|
1314
|
+
* ___
|
|
1315
|
+
* @param columns - Column or columns to select.
|
|
1316
|
+
* @example
|
|
1317
|
+
* ```
|
|
1318
|
+
* > const df = pl.DataFrame({
|
|
1319
|
+
* ... "foo": [1, 2, 3],
|
|
1320
|
+
* ... "bar": [6, 7, 8],
|
|
1321
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1322
|
+
* ... });
|
|
1323
|
+
* // df: pl.DataFrame<{
|
|
1324
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
1325
|
+
* // bar: pl.Series<Float64, "bar">;
|
|
1326
|
+
* // ham: pl.Series<Utf8, "ham">;
|
|
1327
|
+
* // }>
|
|
1328
|
+
* > df.select('foo');
|
|
1329
|
+
* // pl.DataFrame<{
|
|
1330
|
+
* // foo: pl.Series<Float64, "foo">;
|
|
1331
|
+
* // }>
|
|
1332
|
+
* shape: (3, 1)
|
|
1333
|
+
* ┌─────┐
|
|
1334
|
+
* │ foo │
|
|
1335
|
+
* │ --- │
|
|
1336
|
+
* │ i64 │
|
|
1337
|
+
* ╞═════╡
|
|
1338
|
+
* │ 1 │
|
|
1339
|
+
* ├╌╌╌╌╌┤
|
|
1340
|
+
* │ 2 │
|
|
1341
|
+
* ├╌╌╌╌╌┤
|
|
1342
|
+
* │ 3 │
|
|
1343
|
+
* └─────┘
|
|
1344
|
+
* ```
|
|
1345
|
+
*/
|
|
1346
|
+
select<U extends keyof S>(...columns: U[]): DataFrame<{
|
|
1347
|
+
[P in U]: S[P];
|
|
1348
|
+
}>;
|
|
1349
|
+
select(...columns: ExprOrString[]): DataFrame<S>;
|
|
1350
|
+
/**
|
|
1351
|
+
* Shift the values by a given period and fill the parts that will be empty due to this operation
|
|
1352
|
+
* with `Nones`.
|
|
1353
|
+
* ___
|
|
1354
|
+
* @param periods - Number of places to shift (may be negative).
|
|
1355
|
+
* @example
|
|
1356
|
+
* ```
|
|
1357
|
+
* > const df = pl.DataFrame({
|
|
1358
|
+
* ... "foo": [1, 2, 3],
|
|
1359
|
+
* ... "bar": [6, 7, 8],
|
|
1360
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1361
|
+
* ... });
|
|
1362
|
+
* > df.shift(1);
|
|
1363
|
+
* shape: (3, 3)
|
|
1364
|
+
* ┌──────┬──────┬──────┐
|
|
1365
|
+
* │ foo ┆ bar ┆ ham │
|
|
1366
|
+
* │ --- ┆ --- ┆ --- │
|
|
1367
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1368
|
+
* ╞══════╪══════╪══════╡
|
|
1369
|
+
* │ null ┆ null ┆ null │
|
|
1370
|
+
* ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
1371
|
+
* │ 1 ┆ 6 ┆ "a" │
|
|
1372
|
+
* ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
1373
|
+
* │ 2 ┆ 7 ┆ "b" │
|
|
1374
|
+
* └──────┴──────┴──────┘
|
|
1375
|
+
* > df.shift(-1)
|
|
1376
|
+
* shape: (3, 3)
|
|
1377
|
+
* ┌──────┬──────┬──────┐
|
|
1378
|
+
* │ foo ┆ bar ┆ ham │
|
|
1379
|
+
* │ --- ┆ --- ┆ --- │
|
|
1380
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1381
|
+
* ╞══════╪══════╪══════╡
|
|
1382
|
+
* │ 2 ┆ 7 ┆ "b" │
|
|
1383
|
+
* ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
1384
|
+
* │ 3 ┆ 8 ┆ "c" │
|
|
1385
|
+
* ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
1386
|
+
* │ null ┆ null ┆ null │
|
|
1387
|
+
* └──────┴──────┴──────┘
|
|
1388
|
+
* ```
|
|
1389
|
+
*/
|
|
1390
|
+
shift(periods: number): DataFrame<S>;
|
|
1391
|
+
shift({ periods }: {
|
|
1392
|
+
periods: number;
|
|
1393
|
+
}): DataFrame<S>;
|
|
1394
|
+
/**
|
|
1395
|
+
* Shift the values by a given period and fill the parts that will be empty due to this operation
|
|
1396
|
+
* with the result of the `fill_value` expression.
|
|
1397
|
+
* ___
|
|
1398
|
+
* @param n - Number of places to shift (may be negative).
|
|
1399
|
+
* @param fillValue - fill null values with this value.
|
|
1400
|
+
* @example
|
|
1401
|
+
* ```
|
|
1402
|
+
* > const df = pl.DataFrame({
|
|
1403
|
+
* ... "foo": [1, 2, 3],
|
|
1404
|
+
* ... "bar": [6, 7, 8],
|
|
1405
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1406
|
+
* ... });
|
|
1407
|
+
* > df.shiftAndFill({n:1, fill_value:0});
|
|
1408
|
+
* shape: (3, 3)
|
|
1409
|
+
* ┌─────┬─────┬─────┐
|
|
1410
|
+
* │ foo ┆ bar ┆ ham │
|
|
1411
|
+
* │ --- ┆ --- ┆ --- │
|
|
1412
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1413
|
+
* ╞═════╪═════╪═════╡
|
|
1414
|
+
* │ 0 ┆ 0 ┆ "0" │
|
|
1415
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1416
|
+
* │ 1 ┆ 6 ┆ "a" │
|
|
1417
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1418
|
+
* │ 2 ┆ 7 ┆ "b" │
|
|
1419
|
+
* └─────┴─────┴─────┘
|
|
1420
|
+
* ```
|
|
1421
|
+
*/
|
|
1422
|
+
shiftAndFill(n: number, fillValue: number): DataFrame<S>;
|
|
1423
|
+
shiftAndFill({ n, fillValue, }: {
|
|
1424
|
+
n: number;
|
|
1425
|
+
fillValue: number;
|
|
1426
|
+
}): DataFrame<S>;
|
|
1427
|
+
/**
|
|
1428
|
+
* Shrink memory usage of this DataFrame to fit the exact capacity needed to hold the data.
|
|
1429
|
+
*/
|
|
1430
|
+
shrinkToFit(): DataFrame<S>;
|
|
1431
|
+
shrinkToFit(inPlace: true): void;
|
|
1432
|
+
shrinkToFit({ inPlace }: {
|
|
1433
|
+
inPlace: true;
|
|
1434
|
+
}): void;
|
|
1435
|
+
/**
|
|
1436
|
+
* Slice this DataFrame over the rows direction.
|
|
1437
|
+
* ___
|
|
1438
|
+
* @param opts
|
|
1439
|
+
* @param opts.offset - Offset index.
|
|
1440
|
+
* @param opts.length - Length of the slice
|
|
1441
|
+
* @example
|
|
1442
|
+
* ```
|
|
1443
|
+
* > const df = pl.DataFrame({
|
|
1444
|
+
* ... "foo": [1, 2, 3],
|
|
1445
|
+
* ... "bar": [6.0, 7.0, 8.0],
|
|
1446
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1447
|
+
* ... });
|
|
1448
|
+
* > df.slice(1, 2); // Alternatively `df.slice({offset:1, length:2})`
|
|
1449
|
+
* shape: (2, 3)
|
|
1450
|
+
* ┌─────┬─────┬─────┐
|
|
1451
|
+
* │ foo ┆ bar ┆ ham │
|
|
1452
|
+
* │ --- ┆ --- ┆ --- │
|
|
1453
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1454
|
+
* ╞═════╪═════╪═════╡
|
|
1455
|
+
* │ 2 ┆ 7 ┆ "b" │
|
|
1456
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1457
|
+
* │ 3 ┆ 8 ┆ "c" │
|
|
1458
|
+
* └─────┴─────┴─────┘
|
|
1459
|
+
* ```
|
|
1460
|
+
*/
|
|
1461
|
+
slice({ offset, length }: {
|
|
1462
|
+
offset: number;
|
|
1463
|
+
length: number;
|
|
1464
|
+
}): DataFrame<S>;
|
|
1465
|
+
slice(offset: number, length: number): DataFrame<S>;
|
|
1466
|
+
/**
|
|
1467
|
+
* Sort the DataFrame by column.
|
|
1468
|
+
* ___
|
|
1469
|
+
* @param by - Column(s) to sort by. Accepts expression input, including selectors. Strings are parsed as column names.
|
|
1470
|
+
* @param descending - Sort in descending order. When sorting by multiple columns, can be specified per column by passing a sequence of booleans.
|
|
1471
|
+
* @param nullsLast - Place null values last; can specify a single boolean applying to all columns or a sequence of booleans for per-column control.
|
|
1472
|
+
* @param maintainOrder - Whether the order should be maintained if elements are equal.
|
|
1473
|
+
*/
|
|
1474
|
+
sort(by: ColumnsOrExpr, descending?: boolean, nullsLast?: boolean, maintainOrder?: boolean): DataFrame<S>;
|
|
1475
|
+
sort({ by, reverse, // deprecated
|
|
1476
|
+
maintainOrder, }: {
|
|
1477
|
+
by: ColumnsOrExpr;
|
|
1478
|
+
/** @param @deprecated *since 0.16.0* Use descending instead */
|
|
1479
|
+
reverse?: boolean;
|
|
1480
|
+
nullsLast?: boolean;
|
|
1481
|
+
maintainOrder?: boolean;
|
|
1482
|
+
}): DataFrame<S>;
|
|
1483
|
+
sort({ by, descending, maintainOrder, }: {
|
|
1484
|
+
by: ColumnsOrExpr;
|
|
1485
|
+
descending?: boolean;
|
|
1486
|
+
nullsLast?: boolean;
|
|
1487
|
+
maintainOrder?: boolean;
|
|
1488
|
+
}): DataFrame<S>;
|
|
1489
|
+
/**
|
|
1490
|
+
* Aggregate the columns of this DataFrame to their standard deviation value.
|
|
1491
|
+
* ___
|
|
1492
|
+
* @example
|
|
1493
|
+
* ```
|
|
1494
|
+
* > const df = pl.DataFrame({
|
|
1495
|
+
* ... "foo": [1, 2, 3],
|
|
1496
|
+
* ... "bar": [6, 7, 8],
|
|
1497
|
+
* ... "ham": ['a', 'b', 'c']
|
|
1498
|
+
* ... });
|
|
1499
|
+
* > df.std();
|
|
1500
|
+
* shape: (1, 3)
|
|
1501
|
+
* ╭─────┬─────┬──────╮
|
|
1502
|
+
* │ foo ┆ bar ┆ ham │
|
|
1503
|
+
* │ --- ┆ --- ┆ --- │
|
|
1504
|
+
* │ f64 ┆ f64 ┆ str │
|
|
1505
|
+
* ╞═════╪═════╪══════╡
|
|
1506
|
+
* │ 1 ┆ 1 ┆ null │
|
|
1507
|
+
* ╰─────┴─────┴──────╯
|
|
1508
|
+
* ```
|
|
1509
|
+
*/
|
|
1510
|
+
std(): DataFrame<S>;
|
|
1511
|
+
/**
|
|
1512
|
+
* Aggregate the columns of this DataFrame to their mean value.
|
|
1513
|
+
* ___
|
|
1514
|
+
*
|
|
1515
|
+
* @param axis - either 0 or 1
|
|
1516
|
+
* @param nullStrategy - this argument is only used if axis == 1
|
|
1517
|
+
*/
|
|
1518
|
+
sum(axis: 1, nullStrategy?: "ignore" | "propagate"): Series;
|
|
1519
|
+
sum(): DataFrame<S>;
|
|
1520
|
+
sum(axis: 0): DataFrame<S>;
|
|
1521
|
+
sum(axis: 1): Series;
|
|
1522
|
+
/**
|
|
1523
|
+
* @example
|
|
1524
|
+
* ```
|
|
1525
|
+
* > const df = pl.DataFrame({
|
|
1526
|
+
* ... "letters": ["c", "c", "a", "c", "a", "b"],
|
|
1527
|
+
* ... "nrs": [1, 2, 3, 4, 5, 6]
|
|
1528
|
+
* ... });
|
|
1529
|
+
* > console.log(df.toString());
|
|
1530
|
+
* shape: (6, 2)
|
|
1531
|
+
* ╭─────────┬─────╮
|
|
1532
|
+
* │ letters ┆ nrs │
|
|
1533
|
+
* │ --- ┆ --- │
|
|
1534
|
+
* │ str ┆ i64 │
|
|
1535
|
+
* ╞═════════╪═════╡
|
|
1536
|
+
* │ "c" ┆ 1 │
|
|
1537
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1538
|
+
* │ "c" ┆ 2 │
|
|
1539
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1540
|
+
* │ "a" ┆ 3 │
|
|
1541
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1542
|
+
* │ "c" ┆ 4 │
|
|
1543
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1544
|
+
* │ "a" ┆ 5 │
|
|
1545
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1546
|
+
* │ "b" ┆ 6 │
|
|
1547
|
+
* ╰─────────┴─────╯
|
|
1548
|
+
* > df.groupby("letters")
|
|
1549
|
+
* ... .tail(2)
|
|
1550
|
+
* ... .sort("letters")
|
|
1551
|
+
* shape: (5, 2)
|
|
1552
|
+
* ╭─────────┬─────╮
|
|
1553
|
+
* │ letters ┆ nrs │
|
|
1554
|
+
* │ --- ┆ --- │
|
|
1555
|
+
* │ str ┆ i64 │
|
|
1556
|
+
* ╞═════════╪═════╡
|
|
1557
|
+
* │ "a" ┆ 3 │
|
|
1558
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1559
|
+
* │ "a" ┆ 5 │
|
|
1560
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1561
|
+
* │ "b" ┆ 6 │
|
|
1562
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1563
|
+
* │ "c" ┆ 2 │
|
|
1564
|
+
* ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1565
|
+
* │ "c" ┆ 4 │
|
|
1566
|
+
* ╰─────────┴─────╯
|
|
1567
|
+
* ```
|
|
1568
|
+
*/
|
|
1569
|
+
tail(length?: number): DataFrame<S>;
|
|
1570
|
+
/**
|
|
1571
|
+
* Converts dataframe object into row oriented javascript objects
|
|
1572
|
+
* @example
|
|
1573
|
+
* ```
|
|
1574
|
+
* > df.toRecords()
|
|
1575
|
+
* [
|
|
1576
|
+
* {"foo":1.0,"bar":"a"},
|
|
1577
|
+
* {"foo":2.0,"bar":"b"},
|
|
1578
|
+
* {"foo":3.0,"bar":"c"}
|
|
1579
|
+
* ]
|
|
1580
|
+
* ```
|
|
1581
|
+
* @category IO
|
|
1582
|
+
*/
|
|
1583
|
+
toRecords(): {
|
|
1584
|
+
[K in keyof S]: DTypeToJs<S[K]> | null;
|
|
1585
|
+
}[];
|
|
1586
|
+
/**
|
|
1587
|
+
* Converts dataframe object into a {@link TabularDataResource}
|
|
1588
|
+
*/
|
|
1589
|
+
toDataResource(): TabularDataResource;
|
|
1590
|
+
/**
|
|
1591
|
+
* Converts dataframe object into HTML
|
|
1592
|
+
*/
|
|
1593
|
+
toHTML(): string;
|
|
1594
|
+
/**
|
|
1595
|
+
* Converts dataframe object into column oriented javascript objects
|
|
1596
|
+
* @example
|
|
1597
|
+
* ```
|
|
1598
|
+
* > df.toObject()
|
|
1599
|
+
* {
|
|
1600
|
+
* "foo": [1,2,3],
|
|
1601
|
+
* "bar": ["a", "b", "c"]
|
|
1602
|
+
* }
|
|
1603
|
+
* ```
|
|
1604
|
+
* @category IO
|
|
1605
|
+
*/
|
|
1606
|
+
toObject(): {
|
|
1607
|
+
[K in keyof S]: DTypeToJs<S[K] | null>[];
|
|
1608
|
+
};
|
|
1609
|
+
toSeries(index?: number): SchemaToSeriesRecord<S>[keyof S];
|
|
1610
|
+
toString(): string;
|
|
1611
|
+
/**
|
|
1612
|
+
* Convert a ``DataFrame`` to a ``Series`` of type ``Struct``
|
|
1613
|
+
* @param name Name for the struct Series
|
|
1614
|
+
* @example
|
|
1615
|
+
* ```
|
|
1616
|
+
* > const df = pl.DataFrame({
|
|
1617
|
+
* ... "a": [1, 2, 3, 4, 5],
|
|
1618
|
+
* ... "b": ["one", "two", "three", "four", "five"],
|
|
1619
|
+
* ... });
|
|
1620
|
+
* > df.toStruct("nums");
|
|
1621
|
+
* shape: (5,)
|
|
1622
|
+
* Series: 'nums' [struct[2]{'a': i64, 'b': str}]
|
|
1623
|
+
* [
|
|
1624
|
+
* {1,"one"}
|
|
1625
|
+
* {2,"two"}
|
|
1626
|
+
* {3,"three"}
|
|
1627
|
+
* {4,"four"}
|
|
1628
|
+
* {5,"five"}
|
|
1629
|
+
* ]
|
|
1630
|
+
* ```
|
|
1631
|
+
*/
|
|
1632
|
+
toStruct(name: string): Series;
|
|
1633
|
+
/**
|
|
1634
|
+
* Transpose a DataFrame over the diagonal.
|
|
1635
|
+
*
|
|
1636
|
+
* @remarks This is a very expensive operation. Perhaps you can do it differently.
|
|
1637
|
+
* @param options
|
|
1638
|
+
* @param options.includeHeader If set, the column names will be added as first column.
|
|
1639
|
+
* @param options.headerName If `includeHeader` is set, this determines the name of the column that will be inserted
|
|
1640
|
+
* @param options.columnNames Optional generator/iterator that yields column names. Will be used to replace the columns in the DataFrame.
|
|
1641
|
+
*
|
|
1642
|
+
* @example
|
|
1643
|
+
* > const df = pl.DataFrame({"a": [1, 2, 3], "b": [1, 2, 3]});
|
|
1644
|
+
* > df.transpose({includeHeader:true})
|
|
1645
|
+
* shape: (2, 4)
|
|
1646
|
+
* ┌────────┬──────────┬──────────┬──────────┐
|
|
1647
|
+
* │ column ┆ column_0 ┆ column_1 ┆ column_2 │
|
|
1648
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
1649
|
+
* │ str ┆ i64 ┆ i64 ┆ i64 │
|
|
1650
|
+
* ╞════════╪══════════╪══════════╪══════════╡
|
|
1651
|
+
* │ a ┆ 1 ┆ 2 ┆ 3 │
|
|
1652
|
+
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
|
|
1653
|
+
* │ b ┆ 1 ┆ 2 ┆ 3 │
|
|
1654
|
+
* └────────┴──────────┴──────────┴──────────┘
|
|
1655
|
+
* // replace the auto generated column names with a list
|
|
1656
|
+
* > df.transpose({includeHeader:false, columnNames:["a", "b", "c"]})
|
|
1657
|
+
* shape: (2, 3)
|
|
1658
|
+
* ┌─────┬─────┬─────┐
|
|
1659
|
+
* │ a ┆ b ┆ c │
|
|
1660
|
+
* │ --- ┆ --- ┆ --- │
|
|
1661
|
+
* │ i64 ┆ i64 ┆ i64 │
|
|
1662
|
+
* ╞═════╪═════╪═════╡
|
|
1663
|
+
* │ 1 ┆ 2 ┆ 3 │
|
|
1664
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1665
|
+
* │ 1 ┆ 2 ┆ 3 │
|
|
1666
|
+
* └─────┴─────┴─────┘
|
|
1667
|
+
*
|
|
1668
|
+
* // Include the header as a separate column
|
|
1669
|
+
* > df.transpose({
|
|
1670
|
+
* ... includeHeader:true,
|
|
1671
|
+
* ... headerName:"foo",
|
|
1672
|
+
* ... columnNames:["a", "b", "c"]
|
|
1673
|
+
* ... })
|
|
1674
|
+
* shape: (2, 4)
|
|
1675
|
+
* ┌─────┬─────┬─────┬─────┐
|
|
1676
|
+
* │ foo ┆ a ┆ b ┆ c │
|
|
1677
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
1678
|
+
* │ str ┆ i64 ┆ i64 ┆ i64 │
|
|
1679
|
+
* ╞═════╪═════╪═════╪═════╡
|
|
1680
|
+
* │ a ┆ 1 ┆ 2 ┆ 3 │
|
|
1681
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1682
|
+
* │ b ┆ 1 ┆ 2 ┆ 3 │
|
|
1683
|
+
* └─────┴─────┴─────┴─────┘
|
|
1684
|
+
*
|
|
1685
|
+
* // Replace the auto generated column with column names from a generator function
|
|
1686
|
+
* > function *namesGenerator() {
|
|
1687
|
+
* ... const baseName = "my_column_";
|
|
1688
|
+
* ... let count = 0;
|
|
1689
|
+
* ... let name = `${baseName}_${count}`;
|
|
1690
|
+
* ... count++;
|
|
1691
|
+
* ... yield name;
|
|
1692
|
+
* ... }
|
|
1693
|
+
* > df.transpose({includeHeader:false, columnNames:namesGenerator})
|
|
1694
|
+
* shape: (2, 3)
|
|
1695
|
+
* ┌─────────────┬─────────────┬─────────────┐
|
|
1696
|
+
* │ my_column_0 ┆ my_column_1 ┆ my_column_2 │
|
|
1697
|
+
* │ --- ┆ --- ┆ --- │
|
|
1698
|
+
* │ i64 ┆ i64 ┆ i64 │
|
|
1699
|
+
* ╞═════════════╪═════════════╪═════════════╡
|
|
1700
|
+
* │ 1 ┆ 2 ┆ 3 │
|
|
1701
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1702
|
+
* │ 1 ┆ 2 ┆ 3 │
|
|
1703
|
+
* └─────────────┴─────────────┴─────────────┘
|
|
1704
|
+
*/
|
|
1705
|
+
transpose(options?: {
|
|
1706
|
+
includeHeader?: boolean;
|
|
1707
|
+
headerName?: string;
|
|
1708
|
+
columnNames?: Iterable<string>;
|
|
1709
|
+
}): DataFrame;
|
|
1710
|
+
/**
|
|
1711
|
+
* Drop duplicate rows from this DataFrame.
|
|
1712
|
+
* Note that this fails if there is a column of type `List` in the DataFrame.
|
|
1713
|
+
* @param maintainOrder
|
|
1714
|
+
* @param subset - subset to drop duplicates for
|
|
1715
|
+
* @param keep "first" | "last"
|
|
1716
|
+
*/
|
|
1717
|
+
unique(maintainOrder?: boolean, subset?: ColumnSelection, keep?: "first" | "last"): DataFrame<S>;
|
|
1718
|
+
unique(opts: {
|
|
1719
|
+
maintainOrder?: boolean;
|
|
1720
|
+
subset?: ColumnSelection;
|
|
1721
|
+
keep?: "first" | "last";
|
|
1722
|
+
}): DataFrame<S>;
|
|
1723
|
+
/**
|
|
1724
|
+
Decompose a struct into its fields. The fields will be inserted in to the `DataFrame` on the
|
|
1725
|
+
location of the `struct` type.
|
|
1726
|
+
@param names Names of the struct columns that will be decomposed by its fields
|
|
1727
|
+
@example
|
|
1728
|
+
```
|
|
1729
|
+
> const df = pl.DataFrame({
|
|
1730
|
+
... "int": [1, 2],
|
|
1731
|
+
... "str": ["a", "b"],
|
|
1732
|
+
... "bool": [true, null],
|
|
1733
|
+
... "list": [[1, 2], [3]],
|
|
1734
|
+
... })
|
|
1735
|
+
... .toStruct("my_struct")
|
|
1736
|
+
... .toFrame();
|
|
1737
|
+
> df
|
|
1738
|
+
shape: (2, 1)
|
|
1739
|
+
┌─────────────────────────────┐
|
|
1740
|
+
│ my_struct │
|
|
1741
|
+
│ --- │
|
|
1742
|
+
│ struct[4]{'int',...,'list'} │
|
|
1743
|
+
╞═════════════════════════════╡
|
|
1744
|
+
│ {1,"a",true,[1, 2]} │
|
|
1745
|
+
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1746
|
+
│ {2,"b",null,[3]} │
|
|
1747
|
+
└─────────────────────────────┘
|
|
1748
|
+
> df.unnest("my_struct")
|
|
1749
|
+
shape: (2, 4)
|
|
1750
|
+
┌─────┬─────┬──────┬────────────┐
|
|
1751
|
+
│ int ┆ str ┆ bool ┆ list │
|
|
1752
|
+
│ --- ┆ --- ┆ --- ┆ --- │
|
|
1753
|
+
│ i64 ┆ str ┆ bool ┆ list [i64] │
|
|
1754
|
+
╞═════╪═════╪══════╪════════════╡
|
|
1755
|
+
│ 1 ┆ a ┆ true ┆ [1, 2] │
|
|
1756
|
+
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1757
|
+
│ 2 ┆ b ┆ null ┆ [3] │
|
|
1758
|
+
└─────┴─────┴──────┴────────────┘
|
|
1759
|
+
```
|
|
1760
|
+
*/
|
|
1761
|
+
unnest(names: string | string[]): DataFrame;
|
|
1762
|
+
/**
|
|
1763
|
+
* Aggregate the columns of this DataFrame to their variance value.
|
|
1764
|
+
* @example
|
|
1765
|
+
* ```
|
|
1766
|
+
* > const df = pl.DataFrame({
|
|
1767
|
+
* > "foo": [1, 2, 3],
|
|
1768
|
+
* > "bar": [6, 7, 8],
|
|
1769
|
+
* > "ham": ['a', 'b', 'c']
|
|
1770
|
+
* > });
|
|
1771
|
+
* > df.var()
|
|
1772
|
+
* shape: (1, 3)
|
|
1773
|
+
* ╭─────┬─────┬──────╮
|
|
1774
|
+
* │ foo ┆ bar ┆ ham │
|
|
1775
|
+
* │ --- ┆ --- ┆ --- │
|
|
1776
|
+
* │ f64 ┆ f64 ┆ str │
|
|
1777
|
+
* ╞═════╪═════╪══════╡
|
|
1778
|
+
* │ 1 ┆ 1 ┆ null │
|
|
1779
|
+
* ╰─────┴─────┴──────╯
|
|
1780
|
+
* ```
|
|
1781
|
+
*/
|
|
1782
|
+
var(): DataFrame<S>;
|
|
1783
|
+
/**
|
|
1784
|
+
* Grow this DataFrame vertically by stacking a DataFrame to it.
|
|
1785
|
+
* @param df - DataFrame to stack.
|
|
1786
|
+
* @example
|
|
1787
|
+
* ```
|
|
1788
|
+
* > const df1 = pl.DataFrame({
|
|
1789
|
+
* ... "foo": [1, 2],
|
|
1790
|
+
* ... "bar": [6, 7],
|
|
1791
|
+
* ... "ham": ['a', 'b']
|
|
1792
|
+
* ... });
|
|
1793
|
+
* > const df2 = pl.DataFrame({
|
|
1794
|
+
* ... "foo": [3, 4],
|
|
1795
|
+
* ... "bar": [8 , 9],
|
|
1796
|
+
* ... "ham": ['c', 'd']
|
|
1797
|
+
* ... });
|
|
1798
|
+
* > df1.vstack(df2);
|
|
1799
|
+
* shape: (4, 3)
|
|
1800
|
+
* ╭─────┬─────┬─────╮
|
|
1801
|
+
* │ foo ┆ bar ┆ ham │
|
|
1802
|
+
* │ --- ┆ --- ┆ --- │
|
|
1803
|
+
* │ i64 ┆ i64 ┆ str │
|
|
1804
|
+
* ╞═════╪═════╪═════╡
|
|
1805
|
+
* │ 1 ┆ 6 ┆ "a" │
|
|
1806
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1807
|
+
* │ 2 ┆ 7 ┆ "b" │
|
|
1808
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1809
|
+
* │ 3 ┆ 8 ┆ "c" │
|
|
1810
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1811
|
+
* │ 4 ┆ 9 ┆ "d" │
|
|
1812
|
+
* ╰─────┴─────┴─────╯
|
|
1813
|
+
* ```
|
|
1814
|
+
*/
|
|
1815
|
+
vstack(df: DataFrame<S>): DataFrame<S>;
|
|
1816
|
+
/**
|
|
1817
|
+
* Return a new DataFrame with the column added or replaced.
|
|
1818
|
+
* @param column - Series, where the name of the Series refers to the column in the DataFrame.
|
|
1819
|
+
*/
|
|
1820
|
+
withColumn<SeriesTypeT extends DataType, SeriesNameT extends string>(column: Series<SeriesTypeT, SeriesNameT>): DataFrame<Simplify<S & {
|
|
1821
|
+
[K in SeriesNameT]: SeriesTypeT;
|
|
1822
|
+
}>>;
|
|
1823
|
+
withColumn(column: Series | Expr): DataFrame;
|
|
1824
|
+
withColumns(...columns: (Expr | Series)[]): DataFrame;
|
|
1825
|
+
/**
|
|
1826
|
+
* Return a new DataFrame with the column renamed.
|
|
1827
|
+
* @param existingName
|
|
1828
|
+
* @param replacement
|
|
1829
|
+
*/
|
|
1830
|
+
withColumnRenamed<Existing extends keyof S, New extends string>(existingName: Existing, replacement: New): DataFrame<{
|
|
1831
|
+
[K in keyof S as K extends Existing ? New : K]: S[K];
|
|
1832
|
+
}>;
|
|
1833
|
+
withColumnRenamed(existing: string, replacement: string): DataFrame;
|
|
1834
|
+
withColumnRenamed<Existing extends keyof S, New extends string>(opts: {
|
|
1835
|
+
existingName: Existing;
|
|
1836
|
+
replacement: New;
|
|
1837
|
+
}): DataFrame<{
|
|
1838
|
+
[K in keyof S as K extends Existing ? New : K]: S[K];
|
|
1839
|
+
}>;
|
|
1840
|
+
withColumnRenamed(opts: {
|
|
1841
|
+
existing: string;
|
|
1842
|
+
replacement: string;
|
|
1843
|
+
}): DataFrame;
|
|
1844
|
+
/**
|
|
1845
|
+
* Add a column at index 0 that counts the rows.
|
|
1846
|
+
* @param name - name of the column to add
|
|
1847
|
+
*/
|
|
1848
|
+
withRowCount(name?: string): DataFrame;
|
|
1849
|
+
/** @see {@link filter} */
|
|
1850
|
+
where(predicate: any): DataFrame<S>;
|
|
1851
|
+
/**
|
|
1852
|
+
Upsample a DataFrame at a regular frequency.
|
|
1853
|
+
|
|
1854
|
+
The `every` and `offset` arguments are created with the following string language:
|
|
1855
|
+
- 1ns (1 nanosecond)
|
|
1856
|
+
- 1us (1 microsecond)
|
|
1857
|
+
- 1ms (1 millisecond)
|
|
1858
|
+
- 1s (1 second)
|
|
1859
|
+
- 1m (1 minute)
|
|
1860
|
+
- 1h (1 hour)
|
|
1861
|
+
- 1d (1 calendar day)
|
|
1862
|
+
- 1w (1 calendar week)
|
|
1863
|
+
- 1mo (1 calendar month)
|
|
1864
|
+
- 1q (1 calendar quarter)
|
|
1865
|
+
- 1y (1 calendar year)
|
|
1866
|
+
- 1i (1 index count)
|
|
1867
|
+
|
|
1868
|
+
Or combine them:
|
|
1869
|
+
- "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
|
|
1870
|
+
|
|
1871
|
+
By "calendar day", we mean the corresponding time on the next day (which may not be 24 hours, due to daylight savings).
|
|
1872
|
+
Similarly for "calendar week", "calendar month", "calendar quarter", and "calendar year".
|
|
1873
|
+
|
|
1874
|
+
Parameters
|
|
1875
|
+
----------
|
|
1876
|
+
@param timeColumn Time column will be used to determine a date range.
|
|
1877
|
+
Note that this column has to be sorted for the output to make sense.
|
|
1878
|
+
@param every Interval will start 'every' duration.
|
|
1879
|
+
@param by First group by these columns and then upsample for every group.
|
|
1880
|
+
@param maintainOrder Keep the ordering predictable. This is slower.
|
|
1881
|
+
|
|
1882
|
+
Returns
|
|
1883
|
+
-------
|
|
1884
|
+
DataFrame
|
|
1885
|
+
Result will be sorted by `timeColumn` (but note that if `by` columns are passed, it will only be sorted within each `by` group).
|
|
1886
|
+
|
|
1887
|
+
Examples
|
|
1888
|
+
--------
|
|
1889
|
+
Upsample a DataFrame by a certain interval.
|
|
1890
|
+
|
|
1891
|
+
>>> const df = pl.DataFrame({
|
|
1892
|
+
"date": [
|
|
1893
|
+
new Date(2024, 1, 1),
|
|
1894
|
+
new Date(2024, 3, 1),
|
|
1895
|
+
new Date(2024, 4, 1),
|
|
1896
|
+
new Date(2024, 5, 1),
|
|
1897
|
+
],
|
|
1898
|
+
"groups": ["A", "B", "A", "B"],
|
|
1899
|
+
"values": [0, 1, 2, 3],
|
|
1900
|
+
})
|
|
1901
|
+
.withColumn(pl.col("date").cast(pl.Date).alias("date"))
|
|
1902
|
+
.sort("date");
|
|
1903
|
+
|
|
1904
|
+
>>> df.upsample({timeColumn: "date", every: "1mo", by: "groups", maintainOrder: true})
|
|
1905
|
+
.select(pl.col("*").forwardFill());
|
|
1906
|
+
shape: (7, 3)
|
|
1907
|
+
┌────────────┬────────┬────────┐
|
|
1908
|
+
│ date ┆ groups ┆ values │
|
|
1909
|
+
│ --- ┆ --- ┆ --- │
|
|
1910
|
+
│ date ┆ str ┆ f64 │
|
|
1911
|
+
╞════════════╪════════╪════════╡
|
|
1912
|
+
│ 2024-02-01 ┆ A ┆ 0.0 │
|
|
1913
|
+
│ 2024-03-01 ┆ A ┆ 0.0 │
|
|
1914
|
+
│ 2024-04-01 ┆ A ┆ 0.0 │
|
|
1915
|
+
│ 2024-05-01 ┆ A ┆ 2.0 │
|
|
1916
|
+
│ 2024-04-01 ┆ B ┆ 1.0 │
|
|
1917
|
+
│ 2024-05-01 ┆ B ┆ 1.0 │
|
|
1918
|
+
│ 2024-06-01 ┆ B ┆ 3.0 │
|
|
1919
|
+
└────────────┴────────┴────────┘
|
|
1920
|
+
*/
|
|
1921
|
+
upsample(timeColumn: string, every: string, by?: string | string[], maintainOrder?: boolean): DataFrame<S>;
|
|
1922
|
+
upsample(opts: {
|
|
1923
|
+
timeColumn: string;
|
|
1924
|
+
every: string;
|
|
1925
|
+
by?: string | string[];
|
|
1926
|
+
maintainOrder?: boolean;
|
|
1927
|
+
}): DataFrame<S>;
|
|
1928
|
+
}
|
|
1929
|
+
type DataResourceField = {
|
|
1930
|
+
name: string;
|
|
1931
|
+
type: string;
|
|
1932
|
+
};
|
|
1933
|
+
/**
|
|
1934
|
+
* Tabular Data Resource from https://specs.frictionlessdata.io/schemas/tabular-data-resource.json,
|
|
1935
|
+
*/
|
|
1936
|
+
type TabularDataResource = {
|
|
1937
|
+
data: any[];
|
|
1938
|
+
schema: {
|
|
1939
|
+
fields: DataResourceField[];
|
|
1940
|
+
};
|
|
1941
|
+
};
|
|
1942
|
+
/** @ignore */
|
|
1943
|
+
export declare const _DataFrame: <S extends Schema>(_df: any) => DataFrame<S>;
|
|
1944
|
+
interface DataFrameOptions<S extends Schema = Schema, O extends Partial<S> = any> {
|
|
1945
|
+
columns?: any[];
|
|
1946
|
+
orient?: "row" | "col";
|
|
1947
|
+
schema?: S;
|
|
1948
|
+
schemaOverrides?: O;
|
|
1949
|
+
inferSchemaLength?: number;
|
|
1950
|
+
}
|
|
1951
|
+
/**
|
|
1952
|
+
* DataFrame constructor
|
|
1953
|
+
*/
|
|
1954
|
+
export interface DataFrameConstructor extends Deserialize<DataFrame> {
|
|
1955
|
+
/**
|
|
1956
|
+
* Create an empty DataFrame
|
|
1957
|
+
*/
|
|
1958
|
+
(): DataFrame;
|
|
1959
|
+
/**
|
|
1960
|
+
* Create a DataFrame from a JavaScript object
|
|
1961
|
+
*
|
|
1962
|
+
* @param data - object or array of data
|
|
1963
|
+
* @param options - options
|
|
1964
|
+
* @param options.columns - column names
|
|
1965
|
+
* @param options.orient - orientation of the data [row, col]
|
|
1966
|
+
* Whether to interpret two-dimensional data as columns or as rows. If None, the orientation is inferred by matching the columns and data dimensions. If this does not yield conclusive results, column orientation is used.
|
|
1967
|
+
* @param options.schema - The schema of the resulting DataFrame. The schema may be declared in several ways:
|
|
1968
|
+
*
|
|
1969
|
+
* - As a dict of {name:type} pairs; if type is None, it will be auto-inferred.
|
|
1970
|
+
*
|
|
1971
|
+
* - As a list of column names; in this case types are automatically inferred.
|
|
1972
|
+
*
|
|
1973
|
+
* - As a list of (name,type) pairs; this is equivalent to the dictionary form.
|
|
1974
|
+
*
|
|
1975
|
+
* If you supply a list of column names that does not match the names in the underlying data, the names given here will overwrite them. The number of names given in the schema should match the underlying data dimensions.
|
|
1976
|
+
*
|
|
1977
|
+
* If set to null (default), the schema is inferred from the data.
|
|
1978
|
+
* @param options.schemaOverrides - Support type specification or override of one or more columns; note that any dtypes inferred from the schema param will be overridden.
|
|
1979
|
+
*
|
|
1980
|
+
* @param options.inferSchemaLength - The maximum number of rows to scan for schema inference. If set to None, the full data may be scanned (this can be slow). This parameter only applies if the input data is a sequence or generator of rows; other input is read as-is.
|
|
1981
|
+
* The number of entries in the schema should match the underlying data dimensions, unless a sequence of dictionaries is being passed, in which case a partial schema can be declared to prevent specific fields from being loaded.
|
|
1982
|
+
*
|
|
1983
|
+
* @example
|
|
1984
|
+
* ```
|
|
1985
|
+
* data = {'a': [1n, 2n], 'b': [3, 4]}
|
|
1986
|
+
* df = pl.DataFrame(data)
|
|
1987
|
+
* df
|
|
1988
|
+
* shape: (2, 2)
|
|
1989
|
+
* ╭─────┬─────╮
|
|
1990
|
+
* │ a ┆ b │
|
|
1991
|
+
* │ --- ┆ --- │
|
|
1992
|
+
* │ u64 ┆ i64 │
|
|
1993
|
+
* ╞═════╪═════╡
|
|
1994
|
+
* │ 1 ┆ 3 │
|
|
1995
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1996
|
+
* │ 2 ┆ 4 │
|
|
1997
|
+
* ╰─────┴─────╯
|
|
1998
|
+
* ```
|
|
1999
|
+
*/
|
|
2000
|
+
<T1 extends ArrayLike<Series>>(data: T1, options?: DataFrameOptions): DataFrame<{
|
|
2001
|
+
[K in T1[number] as K["name"]]: K["dtype"];
|
|
2002
|
+
}>;
|
|
2003
|
+
<RecordInput extends Record<string, ArrayLike<any>> = any, S extends Simplify<ArrayLikeLooseRecordToSchema<RecordInput>> = Simplify<ArrayLikeLooseRecordToSchema<RecordInput>>>(data: RecordInput, options?: DataFrameOptions<S>): DataFrame<S>;
|
|
2004
|
+
(data: any, options?: DataFrameOptions): DataFrame;
|
|
2005
|
+
isDataFrame(arg: any): arg is DataFrame;
|
|
2006
|
+
}
|
|
2007
|
+
export declare const DataFrame: DataFrameConstructor;
|
|
2008
|
+
export {};
|