[英]Output Format in Jupyter Notebook
我目前正在使用Jupyter Notebook
進行學習。 我已經按照Datacamp 的 Pandas DataFrame 指南進行Datacamp
我對 Jupyter 筆記本的一件事很好奇:
我有以下代碼段:
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')
輸出
我注意到我的第一個print()
函數將返回分隔線之前的表格。 但是,下面的代碼行df.reset_index().drop_duplicates(subset='index',keep='last').set_index('index')
將返回下面一個漂亮的表格。
我想通過嘗試刪除整個函數print(df)
並轉到新行並輸入df
來對print(df)
執行相同的操作。 結果是我將能夠創建與所示相同的格式。
但是,如果我只是刪除部分print(df)
並將其替換為同一代碼塊中的df
,則無法重新創建相同的格式。
我的問題是:
嘗試將這兩行添加到筆記本的頂部:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
如果這不起作用,您可能會在這里找到答案: IPython Notebook cell multiple output
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.