Skip to content
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

adding left and right view to DataFrame, equivalent to head() and tail() #7005

Closed
wants to merge 2 commits into from

Conversation

michaelaye
Copy link
Contributor

I am working with a lot of columns recently and just thought of these little helpers, basically the same as head() and tail(), but for columns.
Additionally, I fixed a small pep8 issue in head()

@jreback
Copy link
Contributor

jreback commented Apr 29, 2014

ok, nice...can you add tests for them? (can just copy paste from head/tail)?

@michaelaye
Copy link
Contributor Author

oops, my bad. will add them.

"""
Return first n columns
"""
l = self.shape[1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe these should ONLY apply to Frames? (e.g. left/right don't make sense for Series)? so you can move this to core/frame.py

and open another issue to (or here)
add them to core/groupby.py/_dataframe_apply_whitelist (and then the tests in test_groupby.py``

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the core/frame.py issue I understand and completely agree.
What you tried to say after that completely escapes me, sorry. ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahah....

we allow certain methods that be used on a groupby object,

e.g.

df.groupby('A').head() is allowed

that is what the whitelist is for (if you try to use other methods they will raise an error; prevents people from using random methods on groupby objects.

but on second thought...don't worry about this anyhow....

@michaelaye
Copy link
Contributor Author

I am now using it so often, I want to have the corner cases as well:

  • upperleft() = left().head()
  • upperright() = right().head()
  • lowerleft() = left().tail()
  • lowerright() = right().tail()

What do you think?

@jreback
Copy link
Contributor

jreback commented Apr 30, 2014

@jorisvandenbossche ?

related #1889, #2791

@jorisvandenbossche
Copy link
Member

I personally think adding 6 more methods to DataFrame just for this is a bit too much. Only left/right seems better, but also not fully sure.

I think we should think a bit more carefully about this, also related to the default DataFrame display (#6547) and the issues @jreback linked to.
Eg something like df.show('left'), df.show('lowerright'), @michaelaye would this also do? Or this maybe misses the convenience of being able to tab complete and it is not that usefull anymore this way?

Also, if the default DataFrame display will be truncated centrally (#5603), you actually already have somehow left and right in one view?

@cpcloud
Copy link
Member

cpcloud commented Apr 30, 2014

Why not have a corner method that you can pass iloc indices to? Top left would be corner(5,5) bottom left would be corner(-5,5) and so on. You could even implement head on terms of this by accepting None

@jreback
Copy link
Contributor

jreback commented Apr 30, 2014

isn't this what we wanted .show() to be? (or was that paginated)?

@jreback jreback added this to the 0.14.1 milestone Apr 30, 2014
@cpcloud
Copy link
Member

cpcloud commented Apr 30, 2014

Actually corner doesn't really save you anything. Nevermind

@michaelaye
Copy link
Contributor Author

df.show('left') is of course quite longer than df.left() and not tab-completed.
But I totally agree that my feeble attempts here pale in comparison with the linked solutions. As I already noted my feeling that my hacks left me desired to have more specific views in terms of the corners, hence I find one command that can show me the corner cases extremely valuable.

To motivate this further, real-time data analysis is a lot about understanding what your current operation is doing to the data, and a quick view showing me all 4 corners goes a long way towards this.

In this respect, if this can be implemented with one extra command and the default being to show me 2 or 3 rows or columns in the corners, I'm all for it and would recommend to reject my PR. But I also would like to stress that in terms of data visualization I would not find it wise to penny-count the number of methods, I don' think there's many more important things in data analysis than to show how it reacts to the applied operations, so IMHO it would be saving 'at the wrong end'. Nevertheless, I believe @jorisvandenbossche 's comment of 6 added methods for this was more commenting on the lack of power that my PR adds compared to the linked PRs, and here I totally agree.

So, what is the status of the centrally truncated view (i.e. a 4-corner-view), when will it come or is it available in a branch/fork?

Incidentally, I was wondering: Is it possible to automatically adapt the current automatic number of displayed lines and columns as a percent value of the current notebook's width/length?

@immerrr
Copy link
Contributor

immerrr commented May 1, 2014

FWIW, I would too object about adding more "root" methods, but namespace-like df.show.left() seems nice, it would both support tab completion and avoid adding method clutter.

@jreback
Copy link
Contributor

jreback commented May 1, 2014

@immerrr I think that is an excellent idea!

@jreback jreback modified the milestones: 0.15.0, 0.14.1 May 30, 2014
@jreback
Copy link
Contributor

jreback commented Jan 18, 2015

@michaelaye if you'd like to convert this to use a .show namespace I think we'd take that. closing this PR in the mean-time.

@adamrossnelson
Copy link

What about this for a quick method hack chain???

# Display left five columns
df.transpose().head().transpose()

# Display right five columns
df.transpose().tail().transpose()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Output-Formatting __repr__ of pandas objects, to_string Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants