【发布时间】:2019-02-12 23:10:09
【问题描述】:
我想知道是否可以在调试时在 VS Code 中显示 pandas 数据帧(第一张图片),因为它在 PyCharm 中显示(第二张图片)?
感谢您的帮助。
df 打印在 vs 代码中:
df 在 pycharm 中打印:
【问题讨论】:
标签: python pandas debugging dataframe visual-studio-code
我想知道是否可以在调试时在 VS Code 中显示 pandas 数据帧(第一张图片),因为它在 PyCharm 中显示(第二张图片)?
感谢您的帮助。
df 打印在 vs 代码中:
df 在 pycharm 中打印:
【问题讨论】:
标签: python pandas debugging dataframe visual-studio-code
从 python 扩展的January 2021 release 开始,您现在可以在调试原生 python 程序时使用内置数据查看器查看 pandas 数据帧。当程序在断点处停止时,右键单击变量列表中的数据框变量,然后选择“在数据查看器中查看值”
【讨论】:
Tabulate 是一个出色的库,可以实现 pandas df 的精美/漂亮打印:
信息-链接:[https://pypi.org/project/tabulate/]
请按照以下步骤来获得漂亮的打印效果: (注意:为了便于说明,我将在 python 中创建简单的数据框)
1) 安装表格
pip install --upgrade tabulate
此语句将始终安装最新版本的制表库。
2) 导入语句
import pandas as pd
from tabulate import tabulate
3) 创建简单的临时数据框
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) 如果没有表格,我们的数据框打印将是:
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) 使用制表后,您的漂亮打印将是:
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 |
+----+--------+-------+---------------+-----------------+
漂亮又香脆的印刷品,尽情享受吧!!!如果您喜欢我的回答,请添加 cmets!
【讨论】:
attach 模式,请在其中包含您想要中断的breakpoint()。调试时使用debug console:
display(df_consigne_errors)
【讨论】:
我还没有找到 VS Code 的类似功能。如果您需要此功能,您可以考虑使用 Spyder IDE。 Spyder IDE Homepage
【讨论】: