问题
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