4

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.

1
  • 2
    Will print(df1) not work? or you may need from IPython.display import display ? Also, are you getting any error? Commented Apr 14, 2018 at 1:10

4 Answers 4

8

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!

Sign up to request clarification or add additional context in comments.

Comments

5

turns out print(df) works just fine it just took a long time to render due to the size of the table. I tried the suggestions above but had strange errors, eventually this worked print(df['colName']) which lead me to the above... sometimes the solution is the obvious one *facepalm.

Comments

0

Use this:

print("data frame is:\n{}".format(data_pandas))

Comments

-1
df = pandas.read_csv("data.csv")

pandas.set_option('display.max_rows', df.shape[0]+1)

print(df)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.