Pandas set_option - more than one option per line

核能气质少年 提交于 2021-02-10 06:20:17

问题


This may be a stupid question, but....

when setting options after importing pandas I set them one at a time such as:

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

Is there any way to try and combine them. I tried passing a list of options but no worky.

Not a biggy if there is only one way to do it.


回答1:


There isn't a native way to do multiple options on one line. I guess you could do something like:

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

but I wouldn't recommend doing that!

I think writing this longhand is easier to read, more concise, and more pythonic:

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



回答2:


[A couple of years later to the party....]

I know it is an old question, but I found myself often searching for this.

This is my solution based on Andy Hayden solution above. A little bit more readable and uses python 3.X dict.

pd_options = {
'display.max_rows'    : 500,
'display.max_columns' : 500,
'display.width'       : 1000,
}

[pd.set_option(option, setting) for option, setting in pd_options.items()]


来源:https://stackoverflow.com/questions/15900670/pandas-set-option-more-than-one-option-per-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!