DS105W – Data for Data Science
13 Feb 2025
16:03 – 16:15
(Early Insights)
🖥️ Live Demo: Some good practices I saw in your submissions.
dict.get('key', {}) instead of dict['key']for a, b in zip(list_a, list_b)importing the same library in the notebookCode We’ve Seen So Far
for loopsWhere We’re Going
numpy and pandas)16:15 – 16:50
Key Benefits
Core Features
for loops)Say you want to create a new list with the temperatures in Fahrenheit.
Python List
NumPy Types
np.int8 to np.int64np.float32, np.float64np.bool_, np.string_💡 Choose types based on memory needs
🔗 Link: NumPy Data Types
💡 Use & and |, not and/or
⚠️ Using and/or with arrays will fail silently!
Use it like an if-else statement but for arrays.
Say temps = np.array([25, 28, 22, 27, 24]):
You can also chain them together:
Beyond basic arithmetic, NumPy has many built-in functions.
We’ll work in the Jupyter notebook to:
16:50 – 17:15

+ Practice Exercise
I will give you two challenges to solve (in between the break).
numpy💡 The exercises are in the Jupyter notebook I will share at the lecture.
17:15 – 18:00
Key Features
Advantages
.loc and .iloc Attributes.assign MethodAdding New Columns
💡 .assign() is “chainable” and doesn’t modify the original DataFrame
⚠️ Avoid modifying DataFrames in-place:
.apply Method (Series)Apply to Series
.apply Method (DataFrame)Apply to DataFrame
You need to specify axis=1 if you want to apply the function to each row. axis=0 is the default and applies the function to each column.
💡 Pro tip: Chain pandas methods together
THE END
numpy and pandas)![]()
LSE DS105W (2024/25)