One-Click Code Export: SQL, pandas, PySpark and dbt From Your Data Transformations
Build a data clean-up with clicks, then export the steps as DuckDB SQL, Python pandas, PySpark or a dbt model you can review, run and keep in Git.
Open the Data Transformation with code export
Short answer: Data Utility's Export recipe as code turns the steps you build in its Data Transformation tool into DuckDB SQL, Python pandas, PySpark or a dbt model. You get commented, readable code that you can run on a sample and adapt for your own pipeline.
The problem: visual clean-up is fast, but pipelines need code
You open a messy CSV, trim the names, filter out bad rows, join it to a second file and add a calculated column. In a point-and-click tool that takes minutes. Then someone says: "Great, can you put that in the pipeline?" and you start translating every click into SQL or Python from memory.
That translation is where time and mistakes go. You forget that one filter, you change the join type by accident, or you write a slightly different rule for blank cells. A data transformation tool that stops at a downloaded file leaves this step to you.
Why data transformation workflows need code export
A cleaned file is a result. Code is a method. If you only keep the file, the next export from the source system means doing everything again. If you keep the steps as code, you can run them again, review them in a pull request, test them, and hand them to a teammate.
- Repeatability: the same steps run on next month's file.
- Reviewability: a colleague can read the logic instead of trusting a spreadsheet.
- Version control: code goes into Git, a downloaded file does not.
- A faster start: even if the final pipeline looks different, you are editing working code, not writing from scratch.
Introducing One-Click Code Export in Data Utility
Data Utility is a free set of data tools that run in your browser. Its Data Transformation tool lets you load a CSV, JSON, Excel or Parquet file, add steps such as joins, filters, trimming, calculated columns and grouping, and see the result immediately. The files are processed on your device and are not uploaded.
The new Export recipe as code panel sits under the result. It turns the steps you built into code in one of four formats: DuckDB SQL, Python with pandas, PySpark, or a dbt model. Copy it, or download it as a .sql or .py file.
This is a generator for a starting point, not a deployment system. It does not schedule anything or connect to your warehouse. It writes code you can read, run on a sample, and then adapt.
The four export formats
DuckDB SQL
The SQL export is a chain of common table expressions, one per step, each with a comment naming the step. It reads your files with read_csv, read_json_auto, read_parquet or read_xlsx, so you can run it in the DuckDB CLI, in Python, or in the browser (Data Utility can also run SQL on your files right in the page). It is the most direct translation of a recipe, and it is the format we check most closely: every step type is run in the real DuckDB engine and compared with the tool's own result.
Python pandas
The pandas export reads your files into DataFrames and applies one commented block per step: str.strip, boolean masks for filters, merge for joins, groupby for summaries. It is useful for notebooks and scripts. The pandas and PySpark exports are not run automatically in our tests, so run them on a small sample first.
PySpark
The PySpark export builds a SparkSession, reads the files, and uses DataFrame functions (withColumn, filter, join, groupBy and F functions). It is a good starting point when the same logic needs to run on larger data. Treat the generated join keys and casts as something to review for your cluster and schema.
dbt
The dbt export produces a model file: a config line, source() references instead of file paths, the same CTE chain as the SQL export, and the sources block you need to declare. The SQL is written with DuckDB functions, so if your warehouse is Snowflake, BigQuery or Redshift (see the dbt schema.yml generator and CSV to Snowflake too), check function names such as regexp_replace and the SELECT * REPLACE syntax before running it.
A worked example: clean, join and summarize orders
Say you have orders.csv and customers.csv. You want revenue per country, only for orders with a quantity above zero. In Data Transformation you add five steps:
- Trim spaces on the customer column
- Filter rows where qty is greater than 0
- Join with the second file on customer_id (keep all orders)
- Calculated column: revenue = amount × qty
- Group and summarize: sum of revenue per country
Here is the DuckDB SQL that Data Utility generates for exactly that recipe:
-- Generated by Data Utility from your recipe. Runs in DuckDB (CLI, Python or the browser).
WITH
src AS (
SELECT * FROM read_csv('orders.csv')
),
src2 AS (
SELECT * FROM read_csv('customers.csv')
),
step_1 AS ( -- Trim spaces: customer
SELECT * REPLACE (trim(regexp_replace(CAST("customer" AS VARCHAR), '\s+', ' ', 'g')) AS "customer") FROM src
),
step_2 AS ( -- Keep rows where qty greater than "0"
SELECT * FROM step_1 WHERE TRY_CAST("qty" AS DOUBLE) > 0
),
step_3 AS ( -- Join (left) on customer_id = customer_id
SELECT a."order_id", a."customer_id", a."customer", a."amount", a."qty", b."country" FROM step_2 a LEFT JOIN src2 b ON lower(trim(CAST(a."customer_id" AS VARCHAR))) = lower(trim(CAST(b."customer_id" AS VARCHAR))) AND lower(trim(CAST(a."customer_id" AS VARCHAR))) <> ''
),
step_4 AS ( -- New column revenue = amount × qty
SELECT *, TRY_CAST("amount" AS DOUBLE) * TRY_CAST("qty" AS DOUBLE) AS "revenue" FROM step_3
),
step_5 AS ( -- Group by country: sum of revenue
SELECT "country", sum(TRY_CAST("revenue" AS DOUBLE)) AS "sum_revenue" FROM step_4 GROUP BY "country"
)
SELECT * FROM step_5;
-- To save the result: COPY (SELECT * FROM step_5) TO 'result.csv' (HEADER);And the pandas version of the same five steps:
# Generated by Data Utility from your recipe. Needs: pip install pandas numpy
import pandas as pd
import numpy as np
df = pd.read_csv("orders.csv")
df2 = pd.read_csv("customers.csv")
# Step 1: Trim spaces: customer
df["customer"] = df["customer"].str.strip().str.replace(r"\s+", " ", regex=True)
# Step 2: Keep rows where qty greater than "0"
df = df[pd.to_numeric(df["qty"], errors="coerce") > 0]
# Step 3: Join (left) on customer_id = customer_id
df["_k"] = df["customer_id"].astype(str).str.strip().str.lower()
b = df2.copy()
b["_k"] = b["customer_id"].astype(str).str.strip().str.lower()
b["_kb"] = b["customer_id"]
b = b.drop(columns=["customer_id"])
df = df.merge(b, on="_k", how="left")
df = df.drop(columns=["_k", "_kb"])
# Step 4: New column revenue = amount × qty
df["revenue"] = pd.to_numeric(df["amount"], errors="coerce") * pd.to_numeric(df["qty"], errors="coerce")
# Step 5: Group by country: sum of revenue
df = df.assign(_v=pd.to_numeric(df["revenue"], errors="coerce")).groupby(["country"], sort=False, dropna=False)["_v"].sum(min_count=1).reset_index(name="sum_revenue")
print(df.head())
df.to_csv("result.csv", index=False)The PySpark export has the same shape, with F.trim, F.filter, a join on a normalized key, a withColumn for revenue and groupBy("country").agg(F.sum(...)). The dbt export is the SQL above with {{ source('raw', 'orders') }} in place of the file reads. Both are generated from the same recipe, so the steps always agree with each other.
How to export your recipe as code
- Open Data Transformation in Data Utility.
- Load your first file, and a second file if you want to join.
- Add and fill in your steps. A step with missing fields is skipped.
- Check the preview under Result.
- Open Export recipe as code, choose DuckDB SQL, Python (pandas), PySpark or dbt model.
- Copy the code or download it, and run it on a small sample first.
Who benefits
Data engineers can prototype a transformation with a sample file before writing the real job. Analytics engineers can start a dbt model from a visual clean-up. Analysts who know a little SQL or Python get working code they can read and learn from. ETL developers can turn a one-off request into a script, and developers who just need to clean a file once can skip the library lookups.
Real-world use cases
- Turning a manual monthly clean-up into a repeatable script.
- Starting a dbt model from a sample of a new source.
- Agreeing on logic with a teammate: share the SQL, not a screenshot of clicks.
- Learning pandas or PySpark by seeing your own steps written out.
- Prototyping join and group logic before running it on a full dataset.
Manual coding vs. visual transformation plus code export
- Speed to first result: visual steps show the output immediately, while a script needs an edit-run loop.
- Accuracy of the translation: the exporter writes every step the same way each time, instead of retyping logic by hand.
- Control: hand-written code is fully yours; exported code is a starting point you still own and adjust.
- Learning: seeing the same recipe in SQL and pandas side by side makes the differences clear.
Exporting does not replace engineering judgment. You still decide on schemas, performance, tests and scheduling.
Where it fits in a modern data workflow
Use the browser to explore a new file and decide what the clean-up should be. Export the recipe, run it on a sample in DuckDB or pandas, and move the result into your repository: a dbt model, a notebook, or a Spark job. The visual step is the sketch. Your normal engineering process turns it into production code, with tests, review and scheduling.
What to check before you use the exported code
- Run it on a small sample and compare it with the preview.
- Column types are inferred by the engine that runs the code, so a column that looks like a date in one tool may be text in another.
- Blank cells and sort order can behave differently between engines. For example, SQL treats a blank as unknown in a numeric comparison.
- For dbt, adjust function names if your warehouse is not DuckDB.
- Add your own tests and error handling. The export does not do that for you.
Adapting the exported code for your stack
The export is deliberately plain so you can change it. A few things most teams do next:
- Replace the file reads with your real sources: a warehouse table, a dbt source, an S3 path or a database connection.
- Parameterize values that will change, such as the quantity threshold in a filter or the date range.
- Move repeated logic into functions, macros or a shared model so it is not copied between jobs.
- Add tests: not-null and unique checks in dbt, assertions in pandas, or expectations in your data quality tool.
- Check types explicitly. If the source has a schema, cast columns to it instead of relying on inference.
Because every step is labeled with the same description you saw in the tool, it is easy to compare the code with the recipe and to explain the logic to someone who has not seen the file.
Try it
Open the Data Transformation tool, load a sample file, add a few steps and open Export recipe as code. It is free, needs no sign-up, and your data stays in your browser.
Open the Data Transformation with code export
Related tool pages
- Data Transformation: Join, Trim, Concatenate: Join two CSV or Excel files on a key, trim, concatenate, filter, sort, add calculated columns, round, extract text, group and summarize. Pick your steps and download the result. Free, in your browser.
- Delete Columns from a CSV File: Remove one or more columns from a CSV or Excel file and download the result. Free, in your browser, and your file is never uploaded.
- Reorder Columns in a CSV File: Drag columns into a new order, or send a column to the start or the end, in a CSV or Excel file. Free, in your browser, nothing is uploaded.
- Remove Empty Rows and Columns from CSV: Remove rows with empty cells, rows that are completely empty, or columns with no values from a CSV or Excel file. Free, in your browser.
- Find and Replace in a CSV File: Find and replace text in a column of a CSV or Excel file, then download the result. Free, in your browser, and nothing is uploaded.
- Change Date Format in a CSV File: Change the date format of a column in a CSV or Excel file, for example 09/03/2026 to 2026-03-09, or get only the year or month. Free, in your browser.
Also try
- Data Transformation
- dbt schema.yml generator
- CSV to Snowflake
- SQL on your files
- Calculated columns and group by
How to use the Data Transformation with code export: step by step
- Open Data Transformation and load a file (and a second file to join).
- Add and fill in your steps and check the preview.
- Open Export recipe as code under Result.
- Choose DuckDB SQL, pandas, PySpark or dbt, then copy or download the code.
When to use the Data Transformation with code export
- Turning a manual clean-up into a repeatable script
- Starting a dbt model from a sample file
- Prototyping join and group logic before a full run
- Learning pandas or PySpark from your own steps
Example
Input: steps: trim, filter, group by
Output: SELECT city, sum(total) FROM ... GROUP BY city
Frequently asked questions
What is a SQL code generator for data transformations?
It writes SQL from steps you set up visually. In Data Utility, you build a recipe in Data Transformation (trim, filter, join, group and so on) and export it as DuckDB SQL.
Can I generate Python pandas code from my data cleaning steps?
Yes. Export recipe as code offers Python (pandas). Each step becomes a commented block that uses pandas functions such as str.strip, merge and groupby. Run it on a sample first.
How do I generate PySpark code from data transformations?
Build your steps in Data Transformation, open Export recipe as code and choose PySpark. You get a SparkSession, file reads and DataFrame operations for each step.
Does Data Utility support dbt code generation?
It exports a dbt model with source() references and a sources block. The SQL uses DuckDB functions, so check function names if your warehouse is different.
Which export formats are available?
DuckDB SQL, Python (pandas), PySpark and a dbt model.
Is the exported code ready for production?
No. It is a reusable starting point. Review it, test it on a sample, and add your own tests, scheduling and error handling.
Is my data uploaded when I export code?
No. The files are processed in your browser. The exported code reads your original files when you run it yourself.
Which steps can be exported?
Every transformation step in the tool: joins, trimming, case, find and replace, split, rename, remove and reorder columns, filter, remove duplicates, sort, fill, dates, data types, remove empty values, calculated columns, rounding, extract text, padding, group and summarize, keep first or last rows, and clean text.
How accurate is the DuckDB SQL?
Each step type is run in the real DuckDB engine and compared with the tool result in our tests. Edge cases such as blank cells in numeric comparisons and the sort order of mixed-case text can differ.
Is the tool free?
Yes. Data Utility is free and runs in your browser, with no sign-up.
Tip: Run the exported code on a small sample first and compare it with the preview before using it on real data.