<@ULVA73B9P> task has as a result df, when applyin...
# ask-marvin
z
@Marvin task has as a result df, when applying .map() on the task, how do I get the list of the dfs?
m
When you use
.map()
in Prefect to apply a task over an iterable, it returns a list of futures, each representing a task run. To access the results of these mapped tasks, you can use the
.result()
method on each future, which will block until the task run completes and then return the result. Here's a concise way to achieve this:
Copy code
python
from prefect import task, flow

@task
def process_data(data):
    # Your processing logic here
    return data

@flow
def my_flow(data_list):
    futures = process_data.map(data_list)
    results = [future.result() for future in futures]
    return results

dataframes = my_flow(data_list)
In this example,
process_data
is mapped over
data_list
, and each future's result is retrieved using
.result()
. This will give you a list of dataframes, assuming each task returns a dataframe. For more details, you can refer to Prefect's task runners documentation.