Jupyter Notebook:“head”未被识别为内部或外部命令、可操作程序或批处理文件

BSP*_*BSP 5 python deep-learning tensorflow jupyter-notebook

我尝试使用查看我的 CSV 文件

!head {train_file_path} 
Run Code Online (Sandbox Code Playgroud)

在 jupyter 笔记本中。但它会引发错误

'head' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

!head{}在Colab中有效,但在 Jupyter Notebook 中无效。

请帮助我,伙计们。提前致谢

Dav*_*vid 4

使用!意味着您将调用系统命令。如果你在一个Linux/Unix系统上(Google Colab使用这样的系统)那么你可以Linux/Unix直接使用调用命令!。在这种情况下,我假设您正在使用Windows系统,并且该命令head不作为Windows. 假设您使用的是本地托管的Jupyter Notebook,那么它正在系统上运行Windows

您可以使用以下命令通过 Python 执行类似的操作:

with open({train_file_path}) as f:
    for _ in range(10): # first 10 lines
        print(f.readline())
Run Code Online (Sandbox Code Playgroud)