Skip to content

Can't pd.options.display.max_columns = 0 by default? #16579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cbrnr opened this issue Jun 2, 2017 · 7 comments · Fixed by #17023
Closed

Can't pd.options.display.max_columns = 0 by default? #16579

cbrnr opened this issue Jun 2, 2017 · 7 comments · Fixed by #17023
Labels
Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@cbrnr
Copy link
Contributor

cbrnr commented Jun 2, 2017

pd.options.display.max_columns is 20 by default, but when running in a terminal this value could be auto-detected by setting it to 0. I know that this setting can be customized, but for the average user it would be much more convenient if there was no extra step involved. Is there a way to detect if pandas is running in a terminal (where autodetection works)? If so, the value should be set to 0. Otherwise, for example in Jupyter notebooks, it could remain to be 20.

@jreback
Copy link
Contributor

jreback commented Jun 2, 2017

Say you auto-detect (via get_terminal_size) and its 80, then what, how many columns should it be?

This is a pretty reasonable default.

@jreback jreback closed this as completed Jun 2, 2017
@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Jun 2, 2017
@jreback jreback added this to the No action milestone Jun 2, 2017
@cbrnr
Copy link
Contributor Author

cbrnr commented Jun 2, 2017

Maybe I wasn't clear. If the width gets autodetected, a much more reasonable choice for max_columns would be 0. That way, the printed object would fit within the terminal width.

@cbrnr
Copy link
Contributor Author

cbrnr commented Jul 12, 2017

@jreback could you reconsider this? Here's an example to show what I mean:

import numpy as np
import pandas as pd
pd.DataFrame(np.random.rand(5, 10))

In a terminal (mine has 100 columns), the default output of this dataframe looks like this:

          0         1         2         3         4         5         6  \
0  0.173421  0.463432  0.829303  0.557628  0.257765  0.712062  0.129705   
1  0.113790  0.310267  0.076708  0.576933  0.562503  0.623521  0.002787   
2  0.628581  0.740680  0.327314  0.129068  0.816575  0.470844  0.771247   
3  0.947981  0.984844  0.113195  0.449247  0.494137  0.349844  0.207327   
4  0.087635  0.678417  0.255774  0.924561  0.597169  0.089508  0.650698   

          7         8         9  
0  0.817547  0.337570  0.348707  
1  0.051971  0.983914  0.972759  
2  0.566701  0.627593  0.126499  
3  0.619493  0.292824  0.653050  
4  0.530746  0.773546  0.496640  

Now if I set pd.options.display.max_columns = 0, the output looks much nicer:

         0         1         2         3     ...           16        17        18        19
0  0.238365  0.438112  0.307173  0.226128    ...     0.547763  0.319377  0.688708  0.840808
1  0.153844  0.472930  0.128777  0.197224    ...     0.533801  0.530466  0.417650  0.174715
2  0.964627  0.626036  0.433339  0.834303    ...     0.036854  0.248769  0.932532  0.669207
3  0.375633  0.581266  0.026618  0.394931    ...     0.049323  0.195138  0.502164  0.454383
4  0.799988  0.137955  0.067402  0.012556    ...     0.587728  0.226844  0.447049  0.117987

So I was wondering why pd.options.display.max_columns can't be 0 by default?

@jreback
Copy link
Contributor

jreback commented Jul 13, 2017

@TomAugspurger ?

@TomAugspurger
Copy link
Contributor

I usually set the max columns to 0 in my IPython init. I think it would be ok to change the default.

Do we still run into issues where we can't reliably detect the terminal width, or have those all been fixed?

@cbrnr
Copy link
Contributor Author

cbrnr commented Jul 19, 2017

I'll create a PR so that this stays on the radar. I'd also like to propose to change pd.options.display.max_rows to 20 instead of 60, because ideally I'd like to see a summary of the data frame including the column names. This is also how tibbles in R are displayed BTW.

@cbrnr
Copy link
Contributor Author

cbrnr commented Jul 19, 2017

Regarding the detection of the terminal width, I think it doesn't work in PyCharm's integrated terminal. However, the default of 80 is a reasonable value in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants