Python 在VS代码中漂亮地打印熊猫数据帧
我想知道是否有可能在调试时以VS代码显示pandas数据帧(第一张图片),就像在PyCharm中显示一样(第二张图片) 谢谢你的帮助Python 在VS代码中漂亮地打印熊猫数据帧,python,pandas,debugging,dataframe,visual-studio-code,Python,Pandas,Debugging,Dataframe,Visual Studio Code,我想知道是否有可能在调试时以VS代码显示pandas数据帧(第一张图片),就像在PyCharm中显示一样(第二张图片) 谢谢你的帮助 df在vs代码中打印: df在pycharm中打印: 我还没有发现VS代码的类似功能。如果你需要这个特性,你可以考虑使用SydIDID.p> 使用 选择启动模式或启动模式,由您决定 包括一个断点(),如果使用attach模式,则要在此处中断 调试时,请使用以下命令: 制表是一个很好的库,可以实现熊猫df的精美打印: 信息-链接:[ 为了实现漂亮的打印,请遵
df
在vs代码中打印:
df
在pycharm中打印:
我还没有发现VS代码的类似功能。如果你需要这个特性,你可以考虑使用SydIDID.p>
- 使用
- 选择启动模式或启动模式,由您决定
- 包括一个
,如果使用断点()
模式,则要在此处中断attach
- 调试时,请使用以下命令:
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 |
+----+--------+-------+---------------+-----------------+
漂亮且清晰的打印,请欣赏!!!如果您喜欢我的答案,请添加注释!从python扩展开始,您现在可以在调试本机python程序时使用内置的data viewer查看pandas数据帧。当程序在断点处停止时,右键单击变量列表中的dataframe变量并选择“在Data Viewer中查看值”
嘿,谢谢你的回答,但我猜人们正在寻找类似的东西-制表对于我在VS代码中的巨大数据帧非常有用!我想知道为什么它只在“变量”中可用,而不是在“手表”中。有时使用“手表”更方便,例如,当有太多的局部变量时,您需要检索所需的局部变量。但无论如何都有很大的改进。最后,我可以看到我的数据帧!
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 |
+----+--------+-------+---------------+-----------------+