haochengxia / vscode-pydata-viewer

Display PyData files (.npz .npy .pkl .pth) in VSCode.
https://marketplace.visualstudio.com/items?itemName=Percy.vscode-pydata-viewer
MIT License
14 stars 8 forks source link

Visualizing Dataframes with display() #20

Open renato-bosa opened 6 months ago

renato-bosa commented 6 months ago

Hi, thanks for developing this extension!

I'm using this extension to visualize pickle files containing pandas dataframes. However, originally when the dataframes have more than a few columns, the visualization only shows the first and last columns, where I would like to see all the columns.

To address this I created a copy of read_files.py in my local, and modified adding just two lines of code:

elif file_type == FileType.PICKLE.value:
    # Solve pickle files .pkl
    try:
        import pickle

        # set to see all pandas dataframes columns
        import pandas as pd
        pd.set_option('display.max_columns', None)

        contents = []
        with open(file_path, "rb") as f:
        # Code continues...

This two new lines set pandas display options to show all the columns. This change partially worked, allowing all columns to be displayed, but the layout of the text-mode table representation naturally becomes line-breaked and messy.

To address it, I've tried a new version of the file (I can put the code here if needed) that imports and uses display() instead of print(), so I needed to set up Anaconda as the interpreter in the extension settings to make it possible to use display(), but at the end when I run it, the output remained in text-mode, the same as the previous attempt.

What am I missing? How can we develop this feature?

Thanks for your help and for the great work on this extension!