Spyder: View command to open DataFrame in Variable explorer

Created on 5 Sep 2017  路  16Comments  路  Source: spyder-ide/spyder

Description

I come from R with RStudio and I'd like to integrate more Python in my workflow.
With Spyder, I have been able to make this easy. What I've found in Spyder + pandas is really cool and has helped me a bunch.
One feature that I think is comfortable from my previous workbench is the View command, perhaps explore makes more sense in Spyder environment... because of the Variable Explorer.
Say you have a table called my_df, execute
In [7]: explore(my_df)
in the command line, instead of clicking on it in the Variable Explorer. Thus allowing your hands on the keyboard =)

I didn't find a similar command here, so I'm taking the liberty to suggest it.
Cheers.

Versions and main components

  • Spyder Version: 3.2.1
  • Python Version: 3.6.1
  • Qt Version: 5.6.2
  • PyQt Version: 5.6
  • Operating system: Linux-Ubuntu16.04

Dependencies

IPython >=4.0 : 5.3.0 (OK)
cython >=0.21 : 0.25.2 (OK)
jedi >=0.9.0 : 0.10.2 (OK)
nbconvert >=4.0 : 5.1.1 (OK)
numpy >=1.7 : 1.12.1 (OK)
pandas >=0.13.1 : 0.20.1 (OK)
psutil >=0.3 : 5.2.2 (OK)
pycodestyle >=2.3: 2.3.1 (OK)
pyflakes >=0.6.0 : 1.5.0 (OK)
pygments >=2.0 : 2.2.0 (OK)
pylint >=0.25 : 1.6.4 (OK)
qtconsole >=4.2.0: 4.3.0 (OK)
rope >=0.9.4 : 0.9.4-1 (OK)
sphinx >=0.6.6 : 1.5.6 (OK)
sympy >=0.7.3 : 1.0 (OK)

IPython Console Enhancement future

Most helpful comment

another use case: would be make it easier to view a subset of a large dataframe without having to create a temporary variable.
e.g. explore(df['TheColumnICareAbout', 'AnotherColumn'])

As a previously RStudio user transiting to Spyder this would be extremely useful; keyboard use only plus record-wise filtering saves you in cases of significantly sized variables where variable explorer window cannot open.

All 16 comments

@Diego-MX could you describe the actual workflow, or how this command works?

I think @Diego-MX wants to write something like

view(df)

in a console and make it display a Dataframe directly, instead of having to double click on the Variable Explorer.

I have edited my question. Thank you.

@ccordoba12 what do you think? I guess we could have, spyder magics for ipython?

We already have one called %varexp to create plots from the Variable Explorer. We could extend it to provide something like this.

We already have one called %varexp to create plots from the Variable Explorer. We could extend it to provide something like this.

Sounds good. I think a magic is better suited for this right?

Yep, it's the right concept to use.

I would very much like a feature like the one described above by Diego-MX. Was a feature like this ever implemented?

No, sorry. We plan to implement it in Spyder 5, to be released in 2020.

@ccordoba12 Sounds good, thank you for the expedient reply!

another use case: would be make it easier to view a subset of a large dataframe without having to create a temporary variable.
e.g. explore(df['TheColumnICareAbout', 'AnotherColumn'])

@akdor1154, that won't be possible.

@impact27, I think this should be very easy to implement by using the new comms architecture and adding a %view magic to our kernel.

@ccordoba12, is there an architecture where that would be possible? e.g. IPython's display() achieves this workflow in notebooks, and it's really handy.

Then you're welcome to dive in our architecture and implement it, if you think it's possible.

I think the best would be to have a spyder namespace for spyder magic to cleanly separate from ipython magic. something like %spyder display df or %spyder.display df.

What I would see is:
In spyder:

  • in spyder/plugins/variableexplorer, define a new function to display a variable that is not in the variable explorer (for @akdor1154 suggestion) Or that finds the index of the object.
  • in spyder/plugins/ipythonconsole/widgets/shell.py: register a new call_handler: eg. 'display_variable': self.display_variable that will send the received object (or object name if only the index is needed) to the variable explorer.

In spyder-kernels:

  • Register the magic with ipython MagicsManager.register_function (in SpyderKernel I think this is accessed by self.shell.magics_manager.register_function)
  • Send the data to be displayed to the frontend with a comm message to display_variable

another use case: would be make it easier to view a subset of a large dataframe without having to create a temporary variable.
e.g. explore(df['TheColumnICareAbout', 'AnotherColumn'])

As a previously RStudio user transiting to Spyder this would be extremely useful; keyboard use only plus record-wise filtering saves you in cases of significantly sized variables where variable explorer window cannot open.

Was this page helpful?
0 / 5 - 0 ratings