首页 > 解决方案 > 无法使用 df.head(5) 打印前 5 行

问题描述

在这里完成菜鸟。我一直在尝试按照以下说明访问 Kaggle 上的数据集并读取前 5 行。

https://towardsdatascience.com/simple-and-multiple-linear-regression-with-python-c9ab422ec29c

我正在使用 spyder,当我运行以下代码时,我只在控制台中获得了一个运行文件 wdir= 注释

以下是代码:

import pandas as pd
df=pd.read_csv('weight-height.csv')
df.head(5)

输出: 代码和控制台输出

标签: python

解决方案


中篇文章可能正在使用jupyter 笔记本,它将占用最后一行并将其作为格式化输出放在其下方的单元格中,而没有print. 在常规的 python 脚本/空闲或其他 IDE 中,您需要实际使用该print功能打印到终端/控制台。

import pandas as pd

df = pd.read_csv('weight-height.csv')
print(df.head(5))

推荐阅读