Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫:设置最大行数_Python_Formatting_Pandas_Ipython Notebook - Fatal编程技术网

Python 熊猫:设置最大行数

Python 熊猫:设置最大行数,python,formatting,pandas,ipython-notebook,Python,Formatting,Pandas,Ipython Notebook,查看以下数据帧时出现问题: n = 100 foo = DataFrame(index=range(n)) foo['floats'] = np.random.randn(n) foo 问题是它并没有在ipython笔记本中按默认值打印所有行,但我必须切片才能查看结果行。即使以下选项也不会更改输出: pd.set_option('display.max_rows', 500) 有人知道如何显示整个阵列吗?设置display.max_rows: pd.set_option('display.m

查看以下
数据帧时出现问题

n = 100
foo = DataFrame(index=range(n))
foo['floats'] = np.random.randn(n)
foo
问题是它并没有在ipython笔记本中按默认值打印所有行,但我必须切片才能查看结果行。即使以下选项也不会更改输出:

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

有人知道如何显示整个阵列吗?

设置
display.max_rows

pd.set_option('display.max_rows', 500)
对于较旧版本的pandas(,如to a,无需修改设置。编写以下内容要简单得多:

print(foo.to_string())

正如@hanleyhansen在评论中指出的,从版本0.18.1开始,
display.height
选项已被弃用,并表示“使用
display.max_rows
”。因此,您只需按如下方式配置它:

from IPython.display import display
with pd.option_context('display.max_rows', 100, 'display.max_columns', 10):
    display(df) #need display to show the dataframe when using with in jupyter
    #some pandas stuff
pd.set_option('display.max_rows', 500)
pd.options.display.max_rows
60
pd.reset_option('display.max_rows')
见:

不推荐使用的display.height、display.width现在只是一个格式选项,不控制摘要的触发,类似于<0.11.0


就我个人而言,我喜欢直接用赋值语句设置选项,因为多亏了iPython,通过制表符补全很容易找到。我发现很难记住确切的选项名称,所以这种方法对我来说很有效

例如,我必须记住的是,它以
pd.options

pd.options.<TAB>

从这里,我通常输出当前值如下:

from IPython.display import display
with pd.option_context('display.max_rows', 100, 'display.max_columns', 10):
    display(df) #need display to show the dataframe when using with in jupyter
    #some pandas stuff
pd.set_option('display.max_rows', 500)
pd.options.display.max_rows
60
pd.reset_option('display.max_rows')
然后我将其设置为我想要的:

pd.options.display.max_rows = 100
此外,您还应了解选项的上下文管理器,它临时设置代码块内部的选项。请以字符串形式输入选项名称,后跟所需的值。您可以在同一行中输入任意数量的选项:

with pd.option_context('display.max_rows', 100, 'display.max_columns', 10):
    some pandas stuff
您还可以将选项重置回其默认值,如下所示:

from IPython.display import display
with pd.option_context('display.max_rows', 100, 'display.max_columns', 10):
    display(df) #need display to show the dataframe when using with in jupyter
    #some pandas stuff
pd.set_option('display.max_rows', 500)
pd.options.display.max_rows
60
pd.reset_option('display.max_rows')
并重新设置所有这些参数:

pd.reset_option('all')
通过
pd.set_option
设置选项仍然非常好。我只是发现直接使用属性更容易,而且不需要使用
get_option
set_option

已经指出了这一点,但我将尝试对这个问题给出更直接的答案:

from IPython.display import display
import numpy as np
import pandas as pd

n = 100
foo = pd.DataFrame(index=range(n))
foo['floats'] = np.random.randn(n)

with pd.option_context("display.max_rows", foo.shape[0]):
    display(foo)
从0.13.1()开始提供。 根据,

[it]允许您使用一组选项执行代码块,当您退出with块时,这些选项将恢复到先前的设置

pd.set\u选项('display.max\u rows',500)
df
在Jupyter中不起作用
而是使用:

pd.set\u选项('display.max\u rows',500)
测向头(500)

要设置无限行数,请使用

没有

i、 e

现在,笔记本将显示笔记本中所有数据集中的所有行;)

同样,您可以设置为将所有列显示为

pd.set_option('display.max_rows', None)
现在,如果您只使用数据帧运行单元格,而不使用任何head或tail标记 作为


然后它将显示数据框中的所有行和列
df

当我在默认(即没有特殊配置文件)笔记本中运行您的代码时,我会得到一个打印精美的表格,可以滚动所有值。仅供参考,我的熊猫们。uuuu版本uuuu=0.9.1(不确定这是否重要)我指的是常规shell,而不是ipythonI我感觉这可能是0.11+中的一个bug……嗨,安迪。韦斯已经证实了吗?我在哪里可以归档这个bug?有解决方法吗?我刚刚归档了,我知道在0.11中对DataFrame repr做了一些最后的更改,所以我在bug报告中抄送了这些更改。将让您知道重新解决方法。+1对于pd.Description_选项(“显示”),我不知道所有选项高度现在都不推荐使用,因此display.max_rows选项就足够了。对于仅查看已接受答案的人:将
与pd.option_上下文('display.height',500,'display.max_rows',500)一起使用:
仅临时设置。我应该更正或给出实现此目的的最佳方法。使用None,不要限制为500#使用pd.option_上下文临时显示所有行和列('display.max_rows',None',display.max_columns',None):display(df_工具)上述代码将仅在包含代码的单元格中生效,因此无需在其他单元格中重置。不确定这是否是jupyter实验室的问题,但所有这些都不起作用。仅“display.max_rows”=无。不应将其转换为字符串。这不是安迪想要的。@simtim Andy问如何“显示整个阵列”。这将做到这一点,并且比公认的答案简单得多。
带有pd。option_context
是这些答案中最干净的方法;副作用最小。