Python installations, tutorials, and cheat sheets
Installing the Anaconda distribution
The Anaconda distribution includes Python 2, Python 3, JupyterHub, and many common data science packages. The Continuum page has the latest Anaconda distribution. Download Anaconda and follow the installation instructions for Windows, Mac, and Unix machines here.
Windows users:
It is recommended that you launch the conda software, including Python and Jupyter notebooks, from the “Anaconda Prompt” in the “Start Menu.”
To check whether the installation worked, open the command line from the start menu and type ‘python’ on the command line.
If you get an error similar to
“‘python’ is not recognised as an internal or external command, operable program or batch file” read below.
If you want to launch conda, Python, and Jupyter notebook from the command line: For some Windows systems, the installer fails to add the Anaconda directory path to your PATH environment variable. To avoid this problem, during the last step of the installation, look for a checkbox for “Automatically set path” or “add Anaconda to my PATH environment variable.” This checkbox will be unchecked by default and the installer warns you to not check it. For many systems, checking this box will solve the path issue.
If it doesn’t, then you will need to manually add the Anaconda path to your system PATH variable, which will be similar to the process shown here (the difference is that you will want to copy & paste the anaconda path rather than the python path).
Tutorials
This video covers:
- How and why to install the Anaconda distribution. (The installation is shown for Mac OS but the explanations are useful for Windows and Unix users.)
- How and why to create virtual environments
- Several other useful commands and features :
1) Installing python on multiple platforms
2) import numpy :To import the numpy package
Note: The import package commands are Python commands. They should be run from inside Python or inside a Jupyter notebook running on a Python kernel.
3) import matplotlib : To import matplotlib package
4) exit : Exit from python
5) pip list : List of packages that came preinstalled with Anaconda
6) pip install : To install packages
7) conda –help : List the various conda commands
8) conda list : List all the packages in the current environment
9) conda create : Create a virtual environment
10)activate/deactivate: To activate/deactivate the virtual environment on windows
11) source activate/deactivate: To activate/deactivatethe virtual environment on Mac OS
12) which python : Path of python
13) conda env list : List the environments
14) conda remove –name : To remove an environment
This video covers:
- How and why to use Jupyter notebooks for Windows and Mac OS
- How to switch your notebook between Python 3 and Python 2 kernels
- The top Jupyter notebook features and tricks
- Where to find cool Jupyter notebook examples to learn from
- Various commands and features like:
(a) Cell numbers : Order in which cells are executed
(b) Markdown : To translate text to HTML
(c) ! : Interpreted as bash command eg. !pip list
(d) Built in commands in jupyter notebook
(i) Line magics : Starts with % . Applied in the same line.
(1) %pwd : Shows the current working directory
(2) %lsmagic : List all the magic commands
(3) %ls : List all the file and folders in the current working directory
(4) %matplotlib inline : it allows matplotlib chart to be display within the notebook
(ii) Cell magics : Starts with %%. Entire cell will be used as that command arguments
(1) %%HTML : Allows to bring HTML directly without using the markdown
(2) %%Javascript : Everything in the cell is interpreted as java script
(3) %%timit : Execution time of the small code snippets
(e) Displaying and working with dataframes
(f) Export the notebook : Download as HTML (.html), ipython notebook (.ipynb), markdown (.md), python (.py), Pdf via laTex(.pdf)
(g) Open the ipython file in anaconda command shell
(h) Jupyter gallery : Download various notebooks as examples and play around with those notebooks.
Free DataCamp interactive tutorial on Python for Data Science (4–6 hrs.)
Cheat sheets and cheat notebooks
Python
NumPy
Pandas
Matplotlib
Markdown
As you go through these materials, learn names and terms. When you get stuck, you can often google the right terms and find very helpful answers. For example, you could google “python remove item from list”, or “pandas dataframe flatten array”