Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display DataFrame in Jupyter Notebook, Depending on a Condition

In a Jupyter Notebook, I am having a DataFrame named tradelines_df. And I want to display it nicely, depending on a condition. Nicely means like this:

enter image description here

I have tried:

condition = True
if condition:
    tradelines_df

but it is not displayed at all. I can write:

if condition:
    print(tradelines_df)

But it is not nicely displayed: enter image description here

Any ideas here?

like image 956
Vityata Avatar asked Sep 15 '25 14:09

Vityata


1 Answers

just use display. Suppose this dataframe:

df = pd.DataFrame({"year": [2021, 2020, 2019]})
condition = True

Then print it if the condition is true:

if condition: 
    display(df)

enter image description here

like image 79
ljuk Avatar answered Sep 18 '25 10:09

ljuk



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!