I tried to view my CSV file using
!head {train_file_path}
in jupyter notebook.But it raises an error
'head' is not recognized as an internal or external command,
operable program or batch file.
!head{} works in colab but not in Jupyter Notebook.
please help me, guys . Thanks in advance
Using ! means that you will be calling a system command. If you are on a Linux/Unix system (Google Colab uses such system) then you can call Linux/Unix commands directly using !. In this case, I am assuming that you are using a Windows system and the command head does not exist as a command for Windows. Assuming that you are using a locally hosted Jupyter Notebook, then it is running on a Windows system.
You can do something similar through Python using:
with open({train_file_path}) as f:
for _ in range(10): # first 10 lines
print(f.readline())
%%bash works for me
or
conda install posix
https://github.com/jupyter/help/issues/203
I had the same issue even if I installed the Linux Subsystem for Windows and tried to refer Jupyter Lab to bash.exe. This seems to work for terminal sessions in Jupyter Lab, but not in the notebook cells.
A workaround for me was to add a %%bash
at the beginning of each cell with bash commands. Then also remove the ! from the actual commands, like so
%%bash
head iris.csv
Still cannot make it work with an ! directly, but at least it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With