PyCharm: View DataFrame or Series using SciView from the "Evaluate" window with a keyboard shortcut

When using PyCharm for debugging data science code, I often want to view a Pandas DataFrame from PyCharm's interactive debugger. It took me a bit to figure out how to do this from the keyboard — here's what I do:

  1. While debugging, open the "Evaluate" window (bound to cmd-; in my configuration).
  2. Type in the name of the variable for the DataFrame and press enter, which gives me this:
  3. Now the question is how to activate the "View as DataFrame" button with the keyboard (see green arrow above). Turns out you can bind "View as Array" to a keyboard shortcut, which will also trigger "View as DataFrame". So I tab from the "Expression" text field to the "Results" area and then hit my "View as Array" shortcut (cmd-enter). This opens the DataFrame in SciView.

Here's the "View as Array" keyboard shortcut configuration:

I've found "floating mode" to work best with SciView. cmd-w will close SciView in floating mode, but for some reason when I do this, the "Evaluate" window will lose focus and I can't figure out how to focus it again without mousing. Keyboard Meastro to the rescue here:

Open tweet in Twitterific bookmarklet

Source: var x = /twitter.com\/.*\/status\/([0-9]+)/.exec(window.location.href); if(x == null) {alert("Doesn't look like this is a tweet.")} else {window.location='twitterrific:///tweet?id='+x[1]};

Converted to bookmarklet: javascript:(function()%7Bvar%20x%20%3D%20%2Ftwitter.com%5C%2F.*%5C%2Fstatus%5C%2F(%5B0-9%5D%2B)%2F.exec(window.location.href)%3B%20if(x%20%3D%3D%20null)%20%7Balert(%22Doesn't%20look%20like%20this%20is%20a%20tweet.%22)%7D%20else%20%7Bwindow.location%3D'twitterrific%3A%2F%2F%2Ftweet%3Fid%3D'%2Bx%5B1%5D%7D%7D)()

Keyboard Maestro macro to open .pickle file in IPython

I often want to view the contents of .pickle files on my computer. I like doing this in the IPython REPL, so I would manually open a new Terminal window, switch to my data science virtualenv, import pickle, and then load the .pickle file in question into a variable. Sounds like a prime target for automation, eh?

Here's a Keyboard Maestro macro that will take the selected .pickle file in Finder and open it up in IPython (inside iTerm2), assigning it to the variable x.

Here's what it looks like (the macro is triggered through LaunchBar with this custom action):

After the macro runs, I type in x to show the object in the Pickle file (in this case, it's just {"hello": "world"}.

Here's what the macro looks like in Keyboard Maestro:

Here's the code:

Note that this requires your Python virtualenv to be set up like this and you have to have a "data" virtualenv. If either of these things aren't true, you'll need to modify the shell commands in the AppleScript accordingly.

Add padding under each Jupyter cell

Put one of the following in a Jupyter notebook cell and run. If you make changes, clear cell contents, save, and refresh the browser.


All cells:

import IPython.core.display as di

di.display_html("""
$('<style>.cell { margin-bottom: 100px !important;}</style>').appendTo('head');
""", raw=True)

To add padding just after code cells:

import IPython.core.display as di

di.display_html("""
$('<style>.code_cell { margin-bottom: 100px !important;}</style>').appendTo('head');
""", raw=True)

To add padding just between code cells:

import IPython.core.display as di

di.display_html("""
$('<style>.code_cell+.code_cell { margin-top: 100px !important;}</style>').appendTo('head');
""", raw=True)