3

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?

Vityata
  • 42,633
  • 8
  • 55
  • 100

2 Answers2

2

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

ljuk
  • 701
  • 3
  • 12
1

Use display

if condition: 
    display(tradelines_df)
Vaebhav
  • 4,672
  • 1
  • 13
  • 33