Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Eventual Inc Daft DataFrame Write Csv

From Leeroopedia


Knowledge Sources
Domains Data_Engineering, Data_Storage
Last Updated 2026-02-08 00:00 GMT

Overview

Concrete tool for writing DataFrame contents to CSV text files provided by the Daft library.

Description

The write_csv method on Daft's DataFrame class writes the DataFrame as CSV files to a specified root directory. Files are written with randomly generated UUID filenames. It supports three write modes (append, overwrite, overwrite-partitions), Hive-style partitioning, and configurable CSV formatting options including delimiter, quote character, escape character, header toggle, and date/timestamp format strings. The method is a blocking call that triggers full execution of the DataFrame query plan.

Usage

Use df.write_csv() to export DataFrame results to CSV files. This is a method on DataFrame instances. An optional IOConfig can be provided for remote storage credentials.

Code Reference

Source Location

  • Repository: Daft
  • File: daft/dataframe/dataframe.py
  • Lines: L854-964

Signature

def write_csv(
    self,
    root_dir: str | pathlib.Path,
    write_mode: Literal["append", "overwrite", "overwrite-partitions"] = "append",
    partition_cols: list[ColumnInputType] | None = None,
    io_config: IOConfig | None = None,
    delimiter: str | None = None,
    quote: str | None = None,
    escape: str | None = None,
    header: bool | None = True,
    date_format: str | None = None,
    timestamp_format: str | None = None,
) -> DataFrame

Import

import daft

# Method on DataFrame - no separate import needed
df.write_csv("output/")
df.write_csv("output/", write_mode="overwrite")

I/O Contract

Inputs

Name Type Required Description
root_dir str or pathlib.Path Yes Root file path to write CSV files to
write_mode Literal["append", "overwrite", "overwrite-partitions"] No Operation mode. "append" adds new data, "overwrite" replaces all data, "overwrite-partitions" replaces only affected partitions. Defaults to "append".
partition_cols list[ColumnInputType] or None No Columns for Hive-style directory partitioning. Required for "overwrite-partitions" mode.
io_config IOConfig or None No Configuration for remote storage credentials. Defaults to context configuration.
delimiter str or None No Single-character field delimiter. Defaults to comma (",").
quote str or None No Single-character quote character. Defaults to double-quote ('"').
escape str or None No Single-character escape character. Defaults to backslash ("\").
header bool or None No Whether to write a header row. Defaults to True.
date_format str or None No Format string for date columns using chrono strftime format. Defaults to ISO 8601.
timestamp_format str or None No Format string for timestamp columns using chrono strftime format. Defaults to ISO 8601.

Outputs

Name Type Description
return DataFrame A new DataFrame containing the file paths of the written CSV files

Usage Examples

Basic Usage

import daft

df = daft.from_pydict({"x": [1, 2, 3], "y": ["a", "b", "c"]})

# Write to local directory
result = df.write_csv("output_dir", write_mode="overwrite")
result.show()
# Shows paths of written files

Custom Date Format

import daft
import datetime

df = daft.from_pydict({"date": [datetime.date(2024, 1, 15)]})

# Write with DD/MM/YYYY date format
result = df.write_csv("output_dir", date_format="%d/%m/%Y")
# CSV output: 15/01/2024

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment