2015-06-30 35 views
0

看我做的IPython的筆記本電腦和熊貓的第一個步驟(和無法找到谷歌適當的關鍵字...)更改表的大熊貓中

有人能告訴我如何更改表的樣子?在這裏,我希望日期時間不被包裹,縮短列標題以減少單元格的寬度(passenger_count),並舍入浮點數?

enter image description here

+2

你想看看['set_option'(http://pandas.pydata.org/pandas-docs/stable/generated/pandas.set_option.html#pandas.set_option)這些治理顯示/格式化行爲 – EdChum

回答

1

這裏是我的熊貓設置偏愛,並希望它幫助。

import pandas as pd 
# max no. of rows to display 
pd.options.display.max_rows = 30 
# max no. of columns to display 
pd.options.display.max_columns = 6 

# this limit the column width 
pd.options.display.max_colwidth = 10 
# this controls the floating rounding (precision, keep 4 decimals after .) 
pd.options.display.precision = 5 

你可以把這些命令在你的個人資料的IPython配置文件ipython_config.py,這樣每次你一開始無論Qtconsole或筆記本電腦會話,這些設置會被自動加載。

c = get_config() 

c.InteractiveShellApp.exec_lines = [ 
    'import pandas as pd', 
    'pd.options.display.mpl_style = \'default\'', 
    'pd.options.display.max_rows = 30', 
    'pd.options.display.max_columns = 6', 
    'pd.options.display.expand_frame_repr = False', 
    'pd.options.display.max_colwidth = 28', 
    'pd.options.display.precision = 5', 
    'import numpy as np', 
    'np.set_printoptions(precision=4, linewidth=90, threshold=25)', 
    'import matplotlib.pyplot as plt' 
] 
+0

謝謝,分享。但是我最終重命名了這些列。 – marcus

+0

請注意,精度是一個建議,最好使用'float_format' – EdChum