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:PrefectHQ Prefect Save CSV Task

From Leeroopedia


Metadata
Sources Prefect
Domains ETL, Data_Engineering
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete task for persisting a pandas DataFrame to CSV provided by the Prefect ETL example.

Description

The save_csv task writes a DataFrame to disk as CSV and logs a preview of the saved data. It uses pandas' to_csv with index=False and prints a summary.

Code Reference

@task
def save_csv(df: pd.DataFrame, path: Path) -> None:
    """Persist DataFrame to disk then log a preview."""
    df.to_csv(path, index=False)
    print(f"Saved {len(df)} rows → {path}\n\nPreview:\n{df.head()}\n")
  • Import: from prefect import task; import pandas as pd; from pathlib import Path

I/O Contract

Inputs

  • df (pd.DataFrame, required) -- the transformed DataFrame to persist
  • path (Path, required) -- output file path

Outputs

  • None (side effect: CSV file written to disk, preview logged)

Usage Example

from pathlib import Path
from prefect import flow, task
import pandas as pd

@task
def save_csv(df: pd.DataFrame, path: Path) -> None:
    df.to_csv(path, index=False)
    print(f"Saved {len(df)} rows to {path}")

@flow(name="devto_etl", log_prints=True)
def etl():
    df = to_dataframe(raw_pages)
    save_csv(df, Path("devto_articles.csv"))

Related Pages

Page Connections

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