
Installing Python on Windows
The easiest way to install Python on Windows is to use the Windows Store, like this:
1) Open a Command Prompt: Press the Windows and the S keys, then type cmd and press the Enter key.
2) Install python: Type python in the command prompt and press the Enter key. This will open the Windows Store with the Python application. Click the install button to install Python.
3) Check the installation: Run this command back in the command prompt: python --version
Installing Key Libraries
With Python installed, you can now install some essential data science libraries. Open Command Prompt or PowerShell and enter the following commands:
- Press the Windows button and the S button, type ‘cmd’ and hit enter to open a command shell.
- Now create a directory for this project, like
C:\Projects\Jupyter, and change to that directory. - Create a python virtual environment:
python -m venv .venv - Activate the virtual environment:
.venv\scripts\activate - To install polars:
pip install polars - To install Jupyter Lab:
pip install jupyterlab - To install Jupyter Notebook:
pip install notebook - We need to change the directory Jupyter uses to store it’s notebooks. To do that run this command in your Jupyter directory:
jupyter notebook --generate-config - The command will tell you where it created the configuration file. Open the file using Notepad and look for the line that has this:
c.ServerApp.root_dir - Uncomment the line by removing the
#at the beginning of the line and change value to the Jupyter directory you created. The line should look like this:c.ServerApp.root_dir = 'C:\Work\Jupyter' - Save and close the file.
You can also install Black and use it to keep your code formatted like this:
- Run this command:
pip install black jupyter-black
I’ll show how to use it in a notebook later.
Note, you’ll need to run .venv\scripts\activate every time you open a new command shell.
I’ve chosen to start off using Polars rather than Pandas because it is easy to use and much faster than Pandas.
Creating and Running a Sample Jupyter Lab Notebook
Now that you have your tools installed, let’s create and run a sample Jupyter Lab notebook:
1) Open Jupyter Lab: In Command Prompt or PowerShell, activate the venv and then type: jupyter lab
2) The URL to access the notebook is printed, so if it doesn’t open in your browser you can copy the address and go to it in your browser manually.
3) Create a New Notebook: In Jupyter Lab, go to the Launcher tab and select “Python 3” under the Notebook section to create a new notebook.
4) Add and Run Sample Code: In the new notebook, copy and paste the following code into a cell. You may need to remove the whitespace if you get an error:
import polars as pl
df = pl.DataFrame(
{
"foo": [1, 2, 3],
"bar": [6, 7, 8],
"ham": ["a", "b", "c"],
}
)
df
5) Run the Cell: Click the Run button (or press Ctrl + Enter) to execute the cell and see the output. You should see something that looks like this:
shape: (3, 3)
foo bar ham
i64 i64 str
1 6 "a"
2 7 "b"
3 8 "c"


Leave a comment