nodejs-polars
    Preparing search index...

    Interface WriteMethods

    Write methods for DataFrame

    interface WriteMethods {
        writeAvro(
            destination: string | Writable,
            options?: WriteAvroOptions,
        ): void;
        writeAvro(options?: WriteAvroOptions): Buffer;
        writeCSV(dest: string | Writable, options?: CsvWriterOptions): void;
        writeCSV(): Buffer;
        writeCSV(options: CsvWriterOptions): Buffer;
        writeIPC(destination: string | Writable, options?: WriteIPCOptions): void;
        writeIPC(options?: WriteIPCOptions): Buffer;
        writeIPCStream(
            destination: string | Writable,
            options?: WriteIPCOptions,
        ): void;
        writeIPCStream(options?: WriteIPCOptions): Buffer;
        writeJSON(
            destination: string | Writable,
            options?: { format: "lines" | "json" },
        ): void;
        writeJSON(options?: { format: "lines" | "json" }): Buffer;
        writeParquet(
            destination: string | Writable,
            options?: WriteParquetOptions,
        ): void;
        writeParquet(options?: WriteParquetOptions): Buffer;
    }

    Hierarchy (View Summary)

    Index

    Methods - IO

    • Write DataFrame to comma-separated values file (csv).

      If no options are specified, it will return a new string containing the contents


      Parameters

      • dest: string | Writable

        file or stream to write to

      • Optionaloptions: CsvWriterOptions

        Options for

        • OptionalbatchSize?: number
        • OptionaldateFormat?: string
        • OptionaldatetimeFormat?: string
        • OptionalfloatPrecision?: number
        • OptionalincludeBom?: boolean
        • OptionalincludeHeader?: boolean
        • OptionallineTerminator?: string
        • OptionalmaintainOrder?: boolean
        • OptionalnullValue?: string
        • OptionalquoteChar?: string
        • Optionalseparator?: string
        • OptionaltimeFormat?: string

      Returns void

      > const df = pl.DataFrame({
      ... "foo": [1, 2, 3],
      ... "bar": [6, 7, 8],
      ... "ham": ['a', 'b', 'c']
      ... });
      > df.writeCSV();
      foo,bar,ham
      1,6,a
      2,7,b
      3,8,c

      // using a file path
      > df.head(1).writeCSV("./foo.csv")
      // foo.csv
      foo,bar,ham
      1,6,a

      // using a write stream
      > const writeStream = new Stream.Writable({
      ... write(chunk, encoding, callback) {
      ... console.log("writeStream: %O', chunk.toString());
      ... callback(null);
      ... }
      ... });
      > df.head(1).writeCSV(writeStream, {includeHeader: false});
      writeStream: '1,6,a'
    • Returns Buffer

    • Parameters

      Returns Buffer

    • Write Dataframe to JSON string, file, or write stream

      Parameters

      • destination: string | Writable

        file or write stream

      • Optionaloptions: { format: "lines" | "json" }
        • format: "lines" | "json"

          json | lines

      Returns void

      > const df = pl.DataFrame({
      ... foo: [1,2,3],
      ... bar: ['a','b','c']
      ... })

      > df.writeJSON({format:"json"})
      `[ {"foo":1.0,"bar":"a"}, {"foo":2.0,"bar":"b"}, {"foo":3.0,"bar":"c"}]`

      > df.writeJSON({format:"lines"})
      `{"foo":1.0,"bar":"a"}
      {"foo":2.0,"bar":"b"}
      {"foo":3.0,"bar":"c"}`

      // writing to a file
      > df.writeJSON("/path/to/file.json", {format:'lines'})
    • Parameters

      • Optionaloptions: { format: "lines" | "json" }

      Returns Buffer