Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View dataframe while debugging in VS Code

I'm trying to explore switching from PyCharm to VS Code. I can't find a way right now to view my pandas DataFrames in a tabular format while debugging.

When I right click on a df object, there is no option to view.

I have the python extension downloaded. Am I missing something?

enter image description here

like image 710
Christina Zhou Avatar asked Feb 06 '20 14:02

Christina Zhou


People also ask

How can I see debug logs in VS Code?

You can find other debug logs you've downloaded with Visual Studio Code in the . sfdx/tools/debug/logs folder. Right-click any line in the debug log, then choose SFDX: Launch Apex Replay Debugger with Current File.

How do I use Debug Visualizer?

Go to Run > Start Debugging and select an environment (e.g Node. js (preview) ). From the command-palette, select Debug Visualizer: New View .

How do I visualize a DataFrame in Pycharm?

In the Variables tab of the Debug tool window, select an array or a DataFrame. Click a link View as Array/View as DataFrame to the right. Alternatively, you can choose View as Array or View as DataFrame from the context menu. The Data View tool window appears.


Video Answer


4 Answers

Microsoft VSCode team finally made this feature available with latest update of the product. More details could be found in official blog

It works like a charm and is very intuitive. In short:

  1. Set up a break point (by clicking at the left most point of code area, before line number)
  2. Start debugging (Run menu at top have Start Debugging option)
  3. When debugger stops at the debug point, find the required dataframe inside VARIABLES panel. (VARIABLES panel is inside Run and Debug area)
  4. Right click on dataframe and select option View Value in Data Viewer. TADA :)
like image 153
abhiieor Avatar answered Oct 09 '22 12:10

abhiieor


So it looks like this isn't a thing right now in VS Code.

If anyone wants to show their support for the development of this feature, I found this open issue here: https://github.com/microsoft/vscode-python/issues/7063

like image 24
Christina Zhou Avatar answered Oct 09 '22 11:10

Christina Zhou


You can now print the DataFrame in the DEBUG CONSOLE:

enter image description here

From the Github issue mentioned in @Christina Zhou's answer.

like image 31
James Hirschorn Avatar answered Oct 09 '22 10:10

James Hirschorn


My solution for viewing DataFrames in a tabular format while debugging is to simply copy and paste them into an Excel spreadsheet using

df.to_clipboard()

from the debug console. Even some of my colleagues running PyCharm are using this technique, since it gives you way more flexibility to inspect your data.

like image 31
Peter Avatar answered Oct 09 '22 11:10

Peter