如何修复pandas显示表格的方式?

问题描述 投票:-2回答:1

使用pandas 0.24.2。

执行以下操作:

>>> import pandas as pd
>>> pd.DataFrame(range(1000))                     

显示以下内容:

10    10
11    11
12    12
13    13
14    14
15    15
16    16
17    17
18    18
19    19
20    20
21    21
22    22
23    23
24    24
25    25
26    26
27    27
28    28
29    29
..   ...
970  970
971  971
972  972
973  973
974  974
975  975
976  976
977  977
978  978
979  979
980  980
981  981
982  982
983  983
984  984
985  985
986  986
987  987
988  988
989  989
990  990
991  991
992  992
993  993
994  994
995  995
996  996
997  997
998  998
999  999

[1000 rows x 1 columns]
>>> 

也就是说,pd输出的数据太多而且表格不适合一个屏幕。

我看过其他类似的问题,比如:How do I expand the output display to see more columns?,但是他们谈的是pd.utils.terminal,这是我的熊猫版没有的:

>>> pd.util.terminal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pandas.util' has no attribute 'terminal'

按照惯例,熊猫文档没有为此提供任何有用的信息。

两个问题:

  1. 为什么会这样?
  2. 我该如何以自动方式解决这个问题?理想情况下无需设置 将pandas导入pd pd.set_option('display.max_rows',500)pd.set_option('display.max_columns',500)pd.set_option('display.width',1000)

每次我运行python。

python pandas
1个回答
-1
投票

1) Deprecation?

看起来像pandas.util.terminal.get_terminal_size()可能已弃用,因为它不再可用(文档中也没有提到)。

虽然pandas.util使用来自same functionshutil,如果它可以帮助。

2) Python / Ipython startup file

您正在寻找python startup fileipython startup file,它将使用自定义设置启动每个ipython会话。关于pandas配置的更多细节确实表明了in the doc

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.