Skip to main content
 首页 » 编程设计

python之Pandas set_option之每行有多个选项

2025年05月04日15haluo1

这可能是个愚蠢的问题,但是......

在导入 pandas 后设置选项时,我一次设置一个选项,例如:

pd.set_option('max_rows',1000) 
pd.set_option('notebook_repr_html',False) 

有没有办法尝试将它们结合起来。我尝试传递一个选项列表,但没有成功。

如果只有一种方法,那也没什么大不了的。

请您参考如下方法:

没有一种 native 方法可以在一行上执行多个选项。我想你可以这样做:

列表理解

[pd.set_option(option, setting) for option, setting in [('max_rows', 1000), ('notebook_repr_html', False)]] 

但我不建议这样做!

手写(每行一个命令)

我认为写这个手写体更容易阅读,更简洁,也更符合 Python 风格:

pd.set_option('max_rows',1000) 
pd.set_option('notebook_repr_html',False)