Reputation: 107
I'm currently using Jupyter Notebook
for my study purposes. I have follow this guide on Pandas DataFrame by Datacamp
I'm curious about one thing with Jupyter notebook:
I have the following segment of code:
import pandas as pd
import numpy as np
df = pd.DataFrame(data=np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [40, 50, 60], [23, 35, 37]]),
index=[2.5, 12.6, 4.8, 4.8, 2.5],
columns=[48, 49, 50])
print(df)
print('-------------------')
df.reset_index().drop_duplicates(subset='index', keep='last').set_index('index')
Output
I notice that my first print()
function will return the table before the separating line. However, the line of code below, which is df.reset_index().drop_duplicates(subset='index',keep='last').set_index('index')
will return a pretty-looking table below.
I want to to the same thing with print(df)
by trying to remove the whole function print(df)
and go to a new line and type in df
. The result is that i will be able to create the same format as shown.
However, I can't recreate the same format if I just remove the section print(df)
and replace it with df
in the same block of codes.
My question is:
Upvotes: 1
Views: 4035
Reputation: 846
Try to add these 2 lines to the top of your notebook:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
If this doesn't work, you might find an answer here: IPython Notebook cell multiple outputs
Upvotes: 1