2016-01-25 141 views
2

爲了打印熊貓DataFrameSeries全部,我們可以使用pd.set_option('display.max_rows', None)。但是,這似乎並沒有對Index數據類型的工作:印刷熊貓索引全

import pandas as pd 
pd.set_option('display.max_rows', None) 
pd.set_option('display.max_columns', None) # just in case 
d = {i: ['a'] for i in range(1000)} 
df = pd.DataFrame(d) 
print(df.columns) 

將打印

Int64Index([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
     ... 
     990, 991, 992, 993, 994, 995, 996, 997, 998, 999], 
     dtype='int64', length=1000) 

有沒有一種方法,使索引打印全部?

一般來說,有沒有辦法告訴熊貓不要縮寫任何輸出?

(蟒蛇3.5,熊貓0.17.1,但它不應該的問題)

回答

3

這是用於此選項max_seq_items

In [21]: pd.options.display.max_seq_items 
Out[21]: 100 

In [22]: pd.options.display.max_seq_items = 4 

In [23]: pd.Index(range(1000)) 
Out[23]: 
Int64Index([ 0, 1, 
      ... 
      998, 999], dtype='int64', length=1000) 

並將其設置爲None將顯示完整的索引。

+1

與'pd.set_option('display.max_seq_items',None)'相同? – max

+0

的確,這是一樣的 – joris

0

這裏是一個簡潔的方式來獲得你想要的東西:

for i in df.columns: 
    print(i,end=", ") 

end參數的值可以做任何你喜歡的事情,包括默認\n