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.
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)
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.
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.
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
Start the debugger by clicking the debug icon on the side bar and then select Run and Debug
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
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.