Unlocking the Arsenal

Part of the free Generative AI course on LogicWiz, module: Leveling Up Your Powers.

Episode 6: Unlocking the Arsenal

"Don't reinvent the wheel. Stand on the shoulders of giants."


You Don't Have to Build Everything

So far, you've been building Nova's abilities from scratch. That's great for learning. But here's the reality: thousands of brilliant developers have already solved the most common problems and published their solutions as libraries.

Python's ecosystem is Nova's secret weapon:

  • Modules let you split YOUR code across files
  • Packages let you install OTHER people's code
  • Pandas is the #1 library for working with structured data — and Nova will use it to analyze articles, user data, and search results

Time to stop building everything by hand and start leveraging the arsenal.


Modules

A module is a Python file (.py) that contains reusable code. You import it with import:

# mymodule.py
def add(a, b):
    return a + b

# main.py
import mymodule
print(mymodule.add(3, 4))

You can also import specific functions:

from mymodule import add
print(add(3, 4))

{{visual:module-walkthrough}}

{{cell:l6-try-module}}


Packages: Other People's Superpowers

Modules are YOUR code. Packages are the world's code. A package is a folder of modules. It usually contains an __init__.py file that marks it as a package.

You install third-party packages from PyPI (Python Package Index) using pip:

pip install pandas
pip install numpy

Useful pip commands:

  • pip list shows all installed packages
  • pip show pandas shows details about a specific package

In notebook environments like Google Colab, many data science packages (including Pandas) are already installed.


Virtual Environments: Keeping Things Clean

As you install more packages for Nova, you'll want to keep each project's dependencies separate. A virtual environment isolates dependencies per project, preventing version conflicts between projects.

python -m venv myenv       # create
source myenv/bin/activate  # activate (Mac/Linux)
pip install pandas         # install inside the env

Each project should have its own virtual environment.


Meet Pandas: Nova's Data Superpower

This is the library that changes everything. Pandas is a data manipulation and analysis library that makes working with structured data feel effortless. Nova will use it to analyze articles, filter search results, and process user data. It provides two core data structures:

Series (1D)

A Series is a one-dimensional array with labels (indices). When created without explicit labels, it automatically assigns numerical indices starting from 0:

import pandas as pd

s = pd.Series([11, 21, 31, 5, 6, 7])
print(s)
# 0    11
# 1    21
# ...

DataFrame (2D)

A DataFrame is a two-dimensional table with labeled rows and columns. Often created from a dictionary where each key becomes a column name:

data = {"City": ["San Francisco", "San Jose", "Seattle"],
        "Population": [10000, 20000, 500000]}
df = pd.DataFrame(data)
print(df)

Creating from a CSV File

csv_url = "https://raw.githubusercontent.com/agconti/kaggle-titanic/master/data/train.csv"
df = pd.read_csv(csv_url)

{{visual:pandas-frame-walkthrough}}

{{cell:l6-try-pandas}}


Looking Before You Leap: Viewing Data

  • df.head(n) first n rows (default 5)
  • df.tail(n) last n rows (default 5)
  • df.sample(n) random n rows

Never load the entire DataFrame with just df if it has millions of rows. Always use head(), tail(), or sample().


Selecting Columns: Picking What Nova Needs

Nova doesn't need every column in a dataset — just the relevant ones. Access a single column (returns a Series):

df["Age"]
print(type(df["Age"]))   # pandas.core.series.Series

Access multiple columns (returns a DataFrame):

subset = df[["Age", "Name", "Survived"]]
print(type(subset))   # pandas.core.frame.DataFrame

{{visual:columns-walkthrough}}

{{cell:l6-try-columns}}


DataFrame Info and Statistics

.info()

Provides column names, data types, and non-null counts:

df.info()
  • Integers and floats show as int64 / float64
  • Strings show as object

.describe()

Generates descriptive statistics for numeric columns (count, mean, std, min, max, quartiles):

df.describe()

.value_counts()

Returns unique values and their counts in a column:

df["Pclass"].value_counts()

{{visual:df-info-walkthrough}}

{{cell:l6-try-info}}


Filtering: Finding What Matters

This is where Pandas becomes powerful for Nova. Need to find all articles from 2024? All users who asked about AI? Filtering uses boolean conditions. A comparison on a column returns a Series of True/False:

df["Pclass"] == 1   # Series of booleans

Pass that boolean Series to filter the DataFrame:

first_class = df[df["Pclass"] == 1]

Only rows where the condition is True will be included.

Complex Filtering with & (AND)

Use the & operator (not and) for element-wise logical AND:

result = df[(df["Pclass"] == 1) & (df["Sex"] == "female")]

Always wrap each condition in parentheses when using & or |.

{{visual:df-filter-walkthrough}}

{{cell:l6-try-filter}}


Mission 6: Equip Nova with Professional Tools

Time to use real tools:

  • Create a DataFrame from a dictionary (simulated, no pandas needed)
  • Select columns
  • Filter rows using boolean conditions

Complete this mission to solidify your Knowledge Architect title.

Next up: You can load and filter data. But Nova needs to aggregate and analyze — group articles by category, calculate averages, add computed columns. In the next episode, you'll master advanced Pandas and become truly data-fluent...