Skip to content

ENH: pprint index/columns? #6295

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
jseabold opened this issue Feb 7, 2014 · 13 comments · Fixed by #9901
Closed

ENH: pprint index/columns? #6295

jseabold opened this issue Feb 7, 2014 · 13 comments · Fixed by #9901
Labels
Enhancement Indexing Related to indexing on series/frames, not to indexes themselves Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@jseabold
Copy link
Contributor

jseabold commented Feb 7, 2014

I haven't looked at the source yet, but do columns ever get pretty printed? It looks like indices do if it's a DatetimeIndex, but not otherwise.

I often find myself doing

df.columns.tolist()

otherwise it's not really readable.

@jreback
Copy link
Contributor

jreback commented Mar 22, 2014

IIRC display.max_seq_items controls this....

@cpcloud ?

@jseabold
Copy link
Contributor Author

It looks to me like it just truncates the columns with a .... I was thinking more of one column name per row or something that's easier to parse with the eyes.

@jreback
Copy link
Contributor

jreback commented Mar 22, 2014

can you post an example with how you think it should look?

@jseabold
Copy link
Contributor Author

List printing usually works for me. Even the nice lined up columns of tab completion are easier to parse though.

[~/]                                                                            
[3]: df = pd.DataFrame(np.random.rand(20,4), columns=['A really long name', 'Another really long name', 'A third really long name', 'The last column name'])

[~/]
[4]: df.columns
[4]: Index([u'A really long name', u'Another really long name', u'A third really long name', u'The last column name'], dtype='object')

[~/]
[5]: df.columns.to<TAB>
df.columns.to_datetime      df.columns.tofile
df.columns.to_native_types  df.columns.tolist
df.columns.to_series        df.columns.tostring

[~/]
[5]: df.columns.tolist()
[5]: 
['A really long name',
'Another really long name',
'A third really long name',
'The last column name']

@jankatins
Copy link
Contributor

Please, no linebreaks after each element: I usually use the output to copy it and use it as a row selection df[["col", "col2"]] and I was quite happy with this (I seem to remember that df.columns printed column names without quotes, so I had to always use list(df.columns))

This is what ipython currently produces:

In [7]: l = ["a", "b", "c"]

In [8]: l
Out[8]: ['a', 'b', 'c']

In [16]: df = pd.DataFrame(np.random.rand(40,8), columns=['A really long name', 'Another really long name', 'A third really long name', 'The last column name', "a","b","c","d"]
)

In [17]: list(df.columns)
Out[17]: 
['A really long name',
 'Another really long name',
 'A third really long name',
 'The last column name',
 'a',
 'b',
 'c',
 'd']

In [18]: df.columns
Out[18]: Index([u'A really long name', u'Another really long name', u'A third really long name', u'The last column name', u'a', u'b', u'c', u'd'], dtype='object')

@jseabold
Copy link
Contributor Author

The counterargument is that you can always slice .columns, so you really don't need to do any copy and pasting. I'm mainly interested in some solution for readability. It's nearly impossible to see what's actually in the data and where, as I use this day to day. The counterargument to me I guess is just use info. Maybe a column_info property would be nice. I don't think it's worth crowing the namespace for though.

Both sides of this are really arguments for some kind of IDE with a variable browser window pane and tab-completion for selecting variable names... It's still the only thing I miss from using Stata.

@jreback
Copy link
Contributor

jreback commented Mar 24, 2014

This is what ipythons interact can do! (in ipython 2.0)....now to get someone to write it......(for frames)

@jseabold
Copy link
Contributor Author

Well that's interesting. They'll be qtconsole/notebooks-only I take it? Is this the link? I'm way behind on ipython-dev.

@TomAugspurger
Copy link
Contributor

It may be notebook only. I'm guessing the qt console doesn't handle javascript.

@jreback
Copy link
Contributor

jreback commented Mar 24, 2014

yah..i think notebook only

@jreback
Copy link
Contributor

jreback commented Mar 24, 2014

http://jakevdp.github.io/blog/2013/12/05/static-interactive-widgets/

I don't think it would be very hard to have as default a couple of sliders that show the extent of a frame (and then allow hiding/showing of various columns).

@jreback
Copy link
Contributor

jreback commented Mar 29, 2014

http://nbviewer.ipython.org/gist/rossant/9463955

proof of concept!

@jreback jreback added Enhancement Indexing Related to indexing on series/frames, not to indexes themselves labels Mar 8, 2015
@jreback jreback added this to the 0.16.1 milestone Mar 8, 2015
@jreback
Copy link
Contributor

jreback commented Apr 4, 2015

xref #9741

To do this right is actually a bit non-trivial. and will require some refactoring to gather all of the scattered bits of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Indexing Related to indexing on series/frames, not to indexes themselves Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants