My first programming language was in MATLAB in college. I was decent at it and actually enjoyed it when most of my classmates dreaded the classwork and homework. I should’ve realized then that I should redirect my major to reflect my skills. But it took me almost 5 years before I realized that I needed to go back to programming. After some researching on languages that data scientists would need to know, I chose SQL. The basics of SQL came easy to me, since you (for the most part) read it like a sentence in English. Eventually, when I enrolled into General Assembly, I had to learn Python.
If you’re reading this blog, you know what Python is. So I won’t go through the nitty gritty. But General Assembly teaches Python through a web app called Jupyter Notebook. It’s an ingenuous way to read and write Python (or any other coding language) code. As for this blog, I will go through some tips, mostly in Jupyter Notebook, that has helped me save time, make less mistakes, and code better. All keyboard inputs are in the Windows version, so Mac users may have to use slightly different keys.
TAB
Tab will autocomplete all. It doesn’t just autocomplete installed Python libraries, it will autocomplete any objects, functions, or variables that you previously made. I use this button all the time, not only to save time on typing, but to see if what I’m typing makes sense. For example, the sklearn.model_selection library doesn’t contain LinearRegression, but say I didn’t know that. I could type in from sklearn.model_selection import Li
and press tab. If it doesn’t autocomplete, I know that something must be misspelled, the wrong library was used, or the library hasn’t been installed.
ALT-TAB
Alt-tab runs the current cell and makes a new cell below. There’s multiple ways to make a new cell in Jupyter Notebook. Depending on what is selected, you can press ‘a’ or ‘b’ to make a cell above or below the current cell, respectively. But I usually use alt-tab to run the current cell I’m in and proceed to coding away in a new cell underneath. This saves me time by seeing the output of my current cell, and then I usually have the next snippet of code that I want to write based off of the output. I’ve found this to be most useful during EDA of a dataset. Not in any particular order, but in rapid succession, I would run .info(), .dtypes, .shape, .describe(), .head()
among some basic scatter plots or histograms to explore the data.
Shift-Tab
Shift-tab finds out all the information that you have forgotten. You can hold shift and press tab multiple times. Each time you press tab does something different.
One tab: Opens a small window with the parameters and function header. Great for a quick reminder of which parameters you need to pass.
Two tabs: Opens up the function documents with descriptions of the function and parameters. The most important aspect is that, you can scroll down. All that time you spent Googling sklearn objects and which parameters need to be passed? Most of that information is readily available in Jupyter Notebook. I spend more time in my work and not getting distracted by a fresh new Google launch page.
Three tabs: I admit. I don’t use this often, but Jupyter Notebook says that the small window will stay up for ten seconds and you can type in other windows. I usually pull up shift-tab to answer any uncertainties about the function I’m about to run, so I have not yet needed this functionality.
Four tabs: For those who want to read in a nicer, cleaner, and more spaced out window, four tabs will open up a full-width window on the bottom half of your browser. It has the same content as two tabs, but in a more readable space.
I’ve only covered three small functionalities of Jupyter Notebook, and have yet cracked the surface. If you only run python in a terminal, Jupyter Notebook may be the boost you need to become a Python expert, or at the very least a faster Python coder. Thank you for reading, and let me know if you have any cool tips/tricks!