Skip to content

How to loop through a folder of csv files in an asset #23059

Discussion options

You must be logged in to vote

No problem, Resource is a more advanced Dagster concept that we'll bypass using for now.

Here's an example where we just provide a config to the asset that will specify the path to the folder that has the csv files in it. The asset materialization will process all csv files in the folder and then create new files prefixed with "processed_" in their name.

import os
import pandas as pd
from dagster import asset

@asset(config_schema={"csv_directory": str})
def process_csv_files(context):
    csv_directory = context.op_config["csv_directory"]
    
    # List all CSV files in the directory
    csv_files = [f for f in os.listdir(csv_directory) if f.endswith('.csv')]
    
    for csv_file in cs…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@JamarWhitfield
Comment options

@garethbrickman
Comment options

@JamarWhitfield
Comment options

@garethbrickman
Comment options

Answer selected by JamarWhitfield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area: asset Related to Software-Defined Assets
2 participants