skip to Main Content

I imagine this has been covered but after numerous searches I’ve been unable to find an answer.

I’m trying to write some Python code and would like to see the Output of that code, like I would in a Jupyter Notebook, except in VSCode. To be clear I’m not looking to replicate the IN: / OUT: cells of a Jupyter Notebook, just have all my Python Code in the code pane and it’s output in the Output or Terminal Window.

For example if I run the following in Jupyter I see the contents of df, including the column names, the rows, info about the DF

import pandas as pd
    
df = pd.read_csv('test.csv')
df

If I run that same code in VSCode it defaults to the terminal window and I don’t see the df output even when clicking the output tab.

Thank you for your assistance.

2

Answers


  1. To display text in a plain python file you need to use the print() function, unlike Jupyter Notebook where you can just call the variable name and it’ll display the variable, so in this instance you need to change:

    df = pd.read_csv('test.csv')
    df
    

    to:
    df = pd.read_csv(‘test.csv’)
    print(df)
    This new changed code uses the print function to display the value of the df variable.

    Login or Signup to reply.
  2. If you want to see the dataframe output, you can use the Debug Console tab in VSCode.

    Assuming you have a python file with the contents shown in your description (the import and the read_csv line), here’s how you you would do it:

    1. Open the file in VSCode
    2. Press F5 to debug the code and add a breakpoint after loading the csv.
    3. You should be able to check the df contents by typing on the Debug Console

    Check an example below:

    example

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search