125

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

2
  • 3
    While this doesn't fix the issue, do note that typically you will want to view objects under the Debug Console tab the Variables view doesn't provide enough details. Commented Feb 7, 2020 at 23:57
  • 1
    Is there any better way to view the dataframe in vscode apart from Data Viewer option ? Commented Mar 23, 2023 at 4:58

13 Answers 13

161

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

As pointed out by @wisbucky, Jupyter VSCode extension is prerequisite for this functionality.

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 :)

UPDATE: VSCode Jupyter team will be deprecating Data Viewer from Jupyter extension in near future.

Alternative for users is to migrate to Data Wrangler extension. Except the extension change, rest all the DataFrame viewing process will remain exactly same, as described above.

Data Wrangler seems to be faster (in personal test) and also provides Data Summary, Data Filters/Sorts, Viewing/Editing mode, Quick Insights header with descriptive statistics.

Sign up to request clarification or add additional context in comments.

14 Comments

They have removed it now.
"They have removed it now". No, the feature is still there in VS Code (May 2021) with Python extension (June 2021). Just make sure you are right clicking in the Variables panel. It doesn't work in any other panel such as Watch or the source code.
Another important note is that both Python and Jupyter vscode extensions must be installed for View Value in Data Viewer to appear. (The Data Viewer comes from the Jupyter extension.)
It's there only if on root variables. If there is an object, and it's argument is dataframe, it's not possible. You can dynamically create new variable and then display it.
One danger here: the data viewer will round small values (beneath 1e10, looks like) to 0. Printing the dataframe directly will show them as expected.
|
34

You can now print the DataFrame in the DEBUG CONSOLE:

enter image description here

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

Comments

33

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.

2 Comments

In vscode, I run df.to_clipboard() but paste option not available in debug console, am I missing something?
@Toonia I believe the point is to paste to a new Excel spreadsheet, not to the debug console.
14

It seems like currently you can do it only using the Jupyter notebook in VS Code, using the variables explorer.
Jupyter Notebook in VScode - variables explorer

1 Comment

This is also possible from .py files.
9

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

2 Comments

Redirects to issue for Jupyter notebook on VS Code if you find something for VS Code and its python debugger, let us know.
8

you can use the view() function from xlwings library. It will show you the DataFrame in Excel:

import pandas as pd
from xlwings import view

df = pd.DataFrame({'A':[1,2], 'B':[3,4]})
view(df)

A better way would be to convert the function to pandas method:

from pandas.core.base import PandasObject
PandasObject.view = view

now you only need to type:

df.view()

Comments

4

I just want to add a trick that helps me visualize dataframes with many rows in the debug console

By default, the debug console does not display all dataframe rows and substitutes some of them with ... as seen below df-with-cutoff-rows

You can bypass this by changing the pandas settings in the debug console

import pandas as pd
pd.set_option('display.max_rows', None)  # Display all rows

Then you will be able to view all the rows of the dataframe 🍺

df-with-all-rows


In addition if you have a dataframe with many columns you can use the following options to view them

import pandas as pd
pd.set_option('display.max_columns', None) # Display all columns
pd.set_option('display.width', 1000) # Set the width to a high number of chars so that a row is displayed in one line

For the different options and what they do see the pandas user guide

Comments

3

Install the Jupyter extension. This provides the View Value in Data Viewer features.

https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter

Comments

2

The Data Viewer Seems to be still working with the Data Wrangler extension:

https://devblogs.microsoft.com/python/data-wrangler-release/

Right click on a data farme variable in the Variables window and then on "View Value in Data Viewer"

View Value in Data Viewer

And the DF is displayed in the Data Wrangler editor with a bunch of options:

Data Wrangler

Note that it might still require the Jupyter extension as I also have it enable at the time of testing this.

1 Comment

This worked for me after adding Jupyter Extension too. Thanks
1

For any one wondering how to view the content of pandas dataframe in Visual Studio 2022, the following can be done:

  1. Open 'Immediate Window' (Debug->Windows->Immediate)

  2. Optionally run the following commands in the immediate window once:

    pd.set_option('display.max_rows', None)
    pd.set_option('display.width', None)
    
    pd.set_option('display.max_columns', None)
    
  3. now type the variable name in immediate window and enter. You will see the data in the dataframe in the immediate window.

Comments

0

Two more options for vscode are the following ones:

Both require more effort but the view is more helpful.

Comments

0

Download the extensions Data Wrangler and Jupyter. Then right_click your dataframe and select the option to "open in an interactive window". In this window that will show up you click "variables" and then select the data_frame and it will show you a table

Comments

0

Another way to do it if breakpoint is clunky:

command + shift + p (mac os)

'Jupyter: Open variables view' then click on the small two boxes with the arrow.

Personally, I find this easier and you could create a custom shortcut to bring up the 'Jupyter: Open variables view' for speed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.