Photo by rawpixel on Unsplash Crazy about data but afraid of exploring it due to the ever confusing
libraries and frameworks? Show Data is everywhere! from social media sites like facebook, twitter etc. to healthcare and what not! With the advent of cutting edge Machine learning and A.I technologies, the data which was of almost no significance a decade ago is now precious to the people working on these technologies and helping them predict pretty useful things like the detection of cancer at an early stage, Upcoming Weather conditions, Cyber attacks, Credit card fraud detection and what not! With the ever-increasing data in today’s world, we need to understand the data in and out to make meaningful predictions and utilise it in the best way possible for the benefit of the masses. Jupyter Notebook has proved to be a gem for the large data exploration task due to its useful support of libraries and visualisation tools. Not just this! The Jupyter Notebook can even run your UNIX commands that you run on
your terminal! So, let's begin with our journey of exploring the data from the jupyter notebook itself! To run any Unix command on the Jupyter notebook, you need to start the command with an %env filename = Path of the file on which operations are being performed.
headThe !head -n N $filename This command will display the top 'N' lines from the file. tailThe !tail -n N $filenameThis command will display the last 'N' lines from the file. wc
!wc $filename -> Prints total number of lines, words and characters. cat
!cat $filename -> Prints out the content of the file.!cat $filename | wc -l -> Prints out the No. of lines in the file.
grep
!grep -i 'Dawn' $filename -> Prints all the lines containing the sed
Syntax :
!sed -e s/x/y/g $filename ->This will replace all occurences of x with y. So, this was it for the exploration part in the Jupyter Notebook! Hope you guys learnt something new today. About me : I am Ankur Kesharwani, 3rd year Undergrad at JIIT Noida, currently exploring Open source and Data science. Connect with me on LinkedIn and Github. Toggle table of contents sidebar The IPython Notebook allows simple UNIX/Linux commands to be executed in a single input cell. There are no limits but when using, please keep in mind that in contrast to a regular UNIX/Linux shell, start each shell command with a To begin with, the command The command /Users/veit/jupyter-tutorial/docs/basics/ipython The command Passing values to and from the shell¶There is a clever way through which you can access the output of a UNIX/Linux command as a variable in Python. Assign the output of a UNIX/Linux command to a variable as follows: Here the Python variable ['create-delete.ipynb', 'file-system.ipynb', 'grep-find.ipynb', 'index.rst', 'pipes-filters.ipynb', 'regex.ipynb', 'shell-variables.ipynb'] You will see the same result below when executing the pwd command. The current directory is stored in the variable directory: ['/Users/veit/jupyter-tutorial/docs/basics/ipython'] What is LS in jupyter?Using only %ls gives you the list in your current directory.
What is %% capture in Python?IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. from __future__ import print_function import sys. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.
What are magic commands in Jupyter notebook?Types of Magic Commands. Line Magics. They are similar to command line calls. ... . Cell Magics. They have %% character prefix. ... . Built-in line magics. %autocall [mode] ... . %automagic. Magic functions are callable without having to type the initial % if set to 1. ... . %cd. This line magic changes the current directory. ... . Usage. ... . %dhist. ... . %edit.. |