2017-07-05 39 views
1

我跑了Python代碼,並得到了像數據幀輸出:抓取使用Python數據幀中的所有行大熊貓

1 Department of Susta... (2)  Community Services (2) 
2 Department of Commu... (2)  Community Services (2) 
3 Sustainability Vict... (1)  Community Services (1) 
4 Southern Grampians ... (1)  Community Services (1) 
5 Productivity Commis... (1)  Community Services (1) 
6   Parliament of NSW (1)  Community Services (1) 
..       ...       ... 
30  Noosa Shire Council (2)  Sport and Recreation (2) 
31 State Library of Qu... (1)  Sport and Recreation (1) 
32 Emergency Services ... (1)  Sport and Recreation (1) 
33 Department of Susta... (1)  Sport and Recreation (1) 

現在我沒有行的B/W 7至29如何獲取的所有行?

回答

1

這只是顯示問題,我更喜歡:當你退出with

#temporaly display 999 rows 
with pd.option_context('display.max_rows', 999): 
    print (df) 

選項值將自動恢復。

+0

如果我不「與」應用什麼功能? – Arti123

+0

我喜歡這個選項,因爲沒有設置和重置選項是必要的。謝謝。 – jezrael

+0

哦,明白了。只是一般性的問題,爲什麼我們需要重置,爲什麼我們總要關閉文件,這是我們打開進入到下一行代碼? – Arti123

1

從0.20.2開始,pandas默認只顯示60行數據。你可以用

pd.set_option('display.max_rows',n) 

其中n是你希望它顯示的行數改變這種情況。

+0

清晰簡潔。 – Arti123

1

您可以創建這樣一個

def print_full(x): 
    pd.set_option('display.max_rows', len(x)) 
    print(x) 
    pd.reset_option('display.max_rows') 
+0

set_option和reset_option有什麼區別? – Arti123

+0

set_option設置指定選項的值,reset_option將一個或多個選項重置爲默認值。在我們的例子中,我們將max_rows的默認值從15改爲了dataframe的長度。所以reset_option只是回到默認值。 –

+0

欲瞭解更多信息,請檢查該鏈接出[set_option(https://pandas.pydata.org/pandas-docs/stable/generated/pandas.set_option.html)reset_option(https://pandas.pydata.org /pandas-docs/stable/generated/pandas.reset_option.html) –