Pretty print a pandas dataframe in VS Code

前端 未结 4 843
情歌与酒
情歌与酒 2021-02-07 03:45

I\'d like to know if it\'s possible to display a pandas dataframe in VS Code while debugging (first picture) as it is displayed in PyCharm (second picture) ?

Thanks for

相关标签:
4条回答
  • 2021-02-07 04:13

    As of the January 2021 release of the python extension, you can now view pandas dataframes with the built-in data viewer when debugging native python programs. When the program is halted at a breakpoint, right-click the dataframe variable in the variables list and select "View Value in Data Viewer"

    DataViewerWhenDebugging

    0 讨论(0)
  • 2021-02-07 04:16
    • use vs code jupyter notebooks support
    • choose between attach to local script or launch mode, up to you.
    • include a breakpoint() where you want to break if using attach mode.
    • when debugging use the debug console to:

      display(df_consigne_errors)
      
    0 讨论(0)
  • 2021-02-07 04:17

    I have not found a similar feature for VS Code. If you require this feature you might consider using Spyder IDE. Spyder IDE Homepage

    0 讨论(0)
  • 2021-02-07 04:21

    Tabulate is an excellent library to achieve fancy/pretty print of the pandas df:

    information - link: [https://pypi.org/project/tabulate/]

    Please follow following steps in order to achieve pretty print: (Note: For easy illustration I will create simple dataframe in python)

    1) install tabulate

    pip install --upgrade tabulate
    

    This statement will always install latest version of the tabulate library.

    2) import statements

    import pandas as pd
    from tabulate import tabulate
    

    3) create simple temporary dataframe

    temp_data = {'Name': ['Sean', 'Ana', 'KK', 'Kelly', 'Amanda'], 
            'Age': [42, 52, 36, 24, 73], 
            'Maths_Score': [67, 43, 65, 78, 97],
            'English_Score': [78, 98, 45, 67, 64]}
    df = pd.DataFrame(temp_data, columns = ['Name', 'Age', 'Maths_Score', 'English_Score'])
    

    4) without tabulate our dataframe print will be:

    print(df)
    
        Name  Age  Maths_Score  English_Score
    0    Sean   42           67             78
    1     Ana   52           43             98
    2      KK   36           65             45
    3   Kelly   24           78             67
    4  Amanda   73           97             64
    

    5) after using tabulate your pretty print will be :

    print(tabulate(df, headers='keys', tablefmt='psql'))
    
    +----+--------+-------+---------------+-----------------+
    |    | Name   |   Age |   Maths_Score |   English_Score |
    |----+--------+-------+---------------+-----------------|
    |  0 | Sean   |    42 |            67 |              78 |
    |  1 | Ana    |    52 |            43 |              98 |
    |  2 | KK     |    36 |            65 |              45 |
    |  3 | Kelly  |    24 |            78 |              67 |
    |  4 | Amanda |    73 |            97 |              64 |
    +----+--------+-------+---------------+-----------------+
    

    nice and crispy print, enjoy!!! Please add comments, if you like my answer!

    0 讨论(0)
提交回复
热议问题