Menu Home

Viewing Pandas DataFrame in VS Code

In this post I will show you how to access the Data viewer which is a useful tool to review, sort and filter data within a Pandas DataFrame.

Required VS Code Extension

If you have not already done so, add the Python extension for Visual Studio Code from Microsoft.

Code Sample

In the code example below, the English Premier League football is read from a HTML table into a list of DataFrames.

import pandas as pd

url = 'https://www.msn.com/en-au/sport/football/epl/ladder'

df_list = pd.read_html(url)

print(df_list[0])

The last line prints out the contents of the Dataframe. Pandas read_html returns a list so the print function is called and outputs the first and only entry in the list which is found at index 0.

Output via print()

Running the output using using print() gives a satisfactory output that is good enough for a first cut to review the data.

Data Viewer

It is also possible to view Pandas Datagrid with the more interactive Data Viewer. This feature is only available when running a program via the VS Code Debugger.

Step 1

Add a break point to the program by clicking in the gutter. In the example shown below I have added a breakpoint at line 7

Step 2

Start the debugger by clicking the debug icon on the side bar and then select Run and Debug

Step 3

Once the program hits the breakpoint, expand the df_list variable and right click where the red border is marked and then select View Value in Data Viewer

Step 4

With the Data Viewer visible, you can interact with the contents of the DataFrame with sort and filter operations.

Very nice! But is there an easier way?

Whilst the Data viewer is very useful, getting to it by having to run the debugger can be tiresome. If you are aware of a simpler or more elegant method of displaying the Data Viewer please let me know via the comments or by getting in touch.

Categories: Pandas Python

oraclefrontovik

Developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.