Python is the go-to language for data analysis at the time of writing, and we will be reviewing all programming concepts from VBA in Python.

Intro to Terminal

Notes:

  • Terminal is a command-line toolkit that helps us to compile and run code, and navigate the file system within your local machine.
    • For PC users, you will be using Git-bash.
    • For Mac users, you will be using your Terminal.app.
  • These are some of the commands you will use:
    • cd – Change directory
    • cd ~ – Change to the home directory within your local machine
    • ls – Lists files in the current directory
    • pwd – Shows the current directory
    • mkdir {folder_name} – Create a new directory with the specified folder name
    • touch {file_name} – Create an empty file with the specified file name
    • rm {file_name} – Remove a file
    • rm -r {folder_name} – Recursively remove the folder and its contents
    • open . – Opens the current folder on Mac
    • explorer . – Opens the current folder on Windows
    • open {file_name} – Opens a specific file on Mac
    • explorer {file_name} – Opens a specific file on Windows
  • You don’t really have to memorize the commands. You can always refer to a cheatsheet.

Students Do: Terminal

Check Your Anaconda Installation

We want to ensure you can run conda in your local machine.

Creating your own virtual environment

We use virtual environments to isolate our work from our local machine settings.

This is important as you develop analysis and code for companies, where your companies’ system might not have the exact libraries you have in your local machine.

How to create a virtual environment?

We are going to use dev as the name of our new virtual environment.

First, update the conda base environment
	conda deactivate
	conda update conda
	conda update anaconda

If you receive a notification that gives the impression that anaconda is not installed in either your Windows or Mac machine, install it first with:

conda install anaconda

Lastly, setup your base environment with the above updates with the statement here:

conda update -n base -c defaults conda

Second, create a new environment dev using Python3.10 with the default packages from Anaconda

conda create -n dev python=3.10 anaconda -y

Lastly, activate the environment

conda activate dev

If you received an error where it says, CondaError: Run 'conda init' before 'conda activate', we would need to initialize conda within your system first:

  • If you’re using Windows, run: conda init bash
  • For Macs,
    • if you’re running an OS version on that runs bash (typically earlier than 10.15, Catalina), run: conda init bash
    • If you’re running an OS version that runs zsh (typically 10.15 or later), run: conda init zsh
  • If you’re successful, it will indicate if it updated your .bash_profile file within your home directory.
  • Restart your terminal (or Git bash).

Then, run: conda activate dev

How to deactivate or exit the environment?

conda deactivate

Variables

To follow with the examples, open up your Visual Studio Code, and open the folder that stores your DU git repo.

Extra Notes on f-strings:

https://realpython.com/python-f-strings/

Students Do: Hello, Variable World!

INPUTS AND PROMPTS

In the real world, we seldom use input and prompts unless you’re coding a game or building an application for terminal. However, it is still useful to know how it works.

Students Do: Down to Input

Conditionals

We will be reviewing the code within the 07-Ins_Conditionals folder.

Students Do: Conditional Conundrum

Lists

In VBA, we learned about arrays. This is where lists and arrays are semantically the same, except that Python’s flavor of lists can be more dynamic. We will be reviewing the code within the 09-Ins_List folder.

Students Do: Rock, Paper, Scissors

Loops

We will be reviewing the code within the 11-Ins_Loops folder.

Students Do: Number Chain – Loops