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
.
- For PC users, you will be using
- These are some of the commands you will use:
cd
– Change directorycd ~
– Change to the home directory within your local machinels
– Lists files in the current directorypwd
– Shows the current directorymkdir {folder_name}
– Create a new directory with the specified folder nametouch {file_name}
– Create an empty file with the specified file namerm {file_name}
– Remove a filerm -r {folder_name}
– Recursively remove the folder and its contentsopen .
– Opens the current folder on Macexplorer .
– Opens the current folder on Windowsopen {file_name}
– Opens a specific file on Macexplorer {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
Let’s open up the README.md
file to get started.
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 running an OS version on that runs bash (typically earlier than 10.15, Catalina), run:
- 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!
Look at the README.md
to start your activity in the 04-Stu_HelloVariableWorld
folder.
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
Look at the README.md
to start your activity in the Students Do: Down to Input
folder.
Conditionals
We will be reviewing the code within the 07-Ins_Conditionals
folder.
Students Do: Conditional Conundrum
Look at the README.md
to start your activity in the 08-Stu_ConditionalConundrum
folder.
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
Look at the README.md
to start your activity in the 10-Stu_RockPaperScissors
folder.
Loops
We will be reviewing the code within the 11-Ins_Loops
folder.
Students Do: Number Chain – Loops
Look at the README.md
to start your activity in the 12-Stu_NumberChain-Loops
folder.