What's the best way to see the first 10 rows of da...
# ask-community
j
What's the best way to see the first 10 rows of data I've transformed in prefect without running in the cloud? I can manually embed my credentials temporarily and want to do something like this and see the result in the terminal:
Copy code
flow = Flow("myflow")
with flow:
    df = extract(stuff)
print(df.head(10)) # This does not work
k
That won’t work because
df
is not a
DataFrame
. It is a
Task
that eventually resolves to a DataFrame so you need to do the
df.head()
inside a task so that it is deferred also. Otherwise, this will try to execute immediately when
df
doesn’t exist
j
what's the best option to do this fast? Just for local testing
k
Making a task to do it.
Copy code
@task
def the_head(df):
    <http://prefect.context.logger.info|prefect.context.logger.info>(df.head(10)
    return
or you can add the logging statement inside your extract task
The statement above is true for both local and cloud runs
j
k
Add
import prefect
to your script
j
done. how do I set up the flow now? It ran but doesn't print anything
k
Did you use the task in your flow?
Copy code
flow = Flow("myflow")
with flow:
    df = extract(stuff)
    the_head(df)
like this?
j
yes
k
One sec let me try
j
Thanks!!
k
It seems to work for me, can you try this snippet:
Copy code
import pandas as pd
from prefect import Flow, task
import prefect

@task
def extract():
    return pd.DataFrame({"a": [1,2,3,4], "b":[1,2,3,4]})

@task
def the_head(df):
    <http://prefect.context.logger.info|prefect.context.logger.info>(df.head(10))
    return

with Flow("df_test") as flow:
    df = extract()
    the_head(df)

flow.run()
j
That worked, thank you!
k
Of course!
j
@Kevin Kho one other quick
base_df=extract_base(connection_r)
On the above, is "extract_base" the upstream task I might reference later on?
k
It would be
base_df
j
Thank you!