2014-01-22 59 views
0

熊貓打印數據框尺寸在數據幀後的最後一行:禁用數據框尺寸打印

import pandas as pd 
print pd.__version__ 
print pd.DataFrame({'a':[1,2],'b':[3,4]}) 

日期:

0.13.0 
    a b 
0 1 3 
1 2 4 

[2 rows x 2 columns]  <- dimensions 

如何禁用數據框的尺寸的打印?我搜索了一個set_option,但找不到任何相關的。

回答

3

此刻,我不認爲你可以,至少不是沒有加密DataFrame。魔術發生在DataFrame.__unicode__

def __unicode__(self): 
    """ 
    Return a string representation for a particular DataFrame 

    Invoked by unicode(df) in py2 only. Yields a Unicode String in both 
    py2/py3. 
    """ 
    buf = StringIO(u("")) 
    if self._info_repr(): 
     self.info(buf=buf) 
     return buf.getvalue() 

    max_rows = get_option("display.max_rows") 
    max_cols = get_option("display.max_columns") 
    if get_option("display.expand_frame_repr"): 
     width, _ = fmt.get_console_size() 
    else: 
     width = None 
    self.to_string(buf=buf, max_rows=max_rows, max_cols=max_cols, 
        line_width=width, show_dimensions=True) 

    return buf.getvalue() 

,你看到它通過show_dimensions=True不檢查任何選項。你可以叫to_string自己,默認爲show_dimensions=False

>>> df 
    a b 
0 1 3 
1 2 4 

[2 rows x 2 columns] 
>>> print df.to_string() 
    a b 
0 1 3 
1 2 4 
>>> 

ISTM沒有理由不擁有display.show_dimensions選項。

+0

想爲此做一個PR嗎? – Jeff

+0

@Jeff:我有一個差不多準備好了,測試和所有,但'repr(df)'和'df.to_string()'之間的str/unicode區別讓我頭疼。將討論@GH。 – DSM