Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print out dataframe in python

normally using jupyternotes I can import pandas make my dataframe and export to csv.

I'm trying to automate this reoccurring query with a python script. I can't figure out how to test my script because I cant print out the df to screen. In jupyternotes I just need to type out the df name in any cell and it will display.

here what I'm doing

import pandas as pd
def run_agg_query(db):
    df1 = pd.read_sql( "select some query",conn)
    display(df1)

but I cant get the df to display.

like image 221
chowpay Avatar asked Oct 21 '25 05:10

chowpay


1 Answers

I think printing the dataframe as a string should do the job for you. Something like this might work -

print(df.to_string())

Hope this helps!

like image 133
rowana Avatar answered Oct 23 '25 17:10

rowana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!