我试图使用以下方式查看我的CSV文件
!head {train_file_path}
在Jupyter Notebook中运行,但会引发错误。
'head' is not recognized as an internal or external command,
operable program or batch file.
!head{}
在colab中可以正常工作,但在Jupyter Notebook中无法正常工作。
请大家帮忙解决一下,谢谢!
我试图使用以下方式查看我的CSV文件
!head {train_file_path}
在Jupyter Notebook中运行,但会引发错误。
'head' is not recognized as an internal or external command,
operable program or batch file.
!head{}
在colab中可以正常工作,但在Jupyter Notebook中无法正常工作。
请大家帮忙解决一下,谢谢!
使用!
表示您将调用系统命令。如果您在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())
conda install posix
即使我安装了适用于 Windows 的 Linux 子系统并尝试将 Jupyter Lab 引用到 bash.exe,仍然遇到了同样的问题。这似乎对 Jupyter Lab 中的终端会话有效,但不适用于笔记本单元格。
我的解决方法是在每个带有 bash 命令的单元格开头添加 %%bash
。然后从实际命令中也删除 !
,如下所示。
%%bash
head iris.csv
仍然无法直接使用!
使其工作,但至少它可以工作。
试试这个
%alias head powershell -command "& {Get-Content %s -Head 5}"
%head datasets/transfusion.data