Series Data Voyage Training Log

~1 min read

NumPy and Pandas Basics by Problem Solving

Drilling ndarray, shape, slicing and broadcasting through 100 NumPy problems, and DataFrame manipulation, conditional filtering and string methods through Pandas problems, to make the core tools of data analysis routine.

TrainingDataPandas

Two Tools Form the Floor of Analysis

To visualize and preprocess, NumPy and Pandas have to be second nature. I built the basics by solving many problems.

NumPy — The Array Mindset

I repeated the essentials across 100 problems.

import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a.ndim, a.shape)   # dimensions and shape
  • Created and reshaped arrays with arange, linspace, reshape, flatten
  • Used slicing to select rows/columns, the last element, and the first N
  • Learned the broadcasting rules for operating on differently shaped arrays
  • Handled conditions and joins with where, sort, concatenate, transpose
  • Confirmed the dtype rule that np.array(['1', 2, '3']) unifies everything to strings

Pandas — A Language for Tables

countries = pd.DataFrame(data).set_index("country")
countries[countries["density"] > 300][["capital", "population"]]
  • Created derived columns such as density = population / area
  • Extracted countries with density between 100 and 300 by conditional filtering
  • Searched capital names with the string methods str.len() and str.contains("am")
  • Practiced editing values and indexing, and aggregated and explored movie-review data

Takeaway

Key point

NumPy gave me the mindset of numeric arrays, and Pandas gave me a language for questioning tables. The knack of turning "which capitals have density over 300?" into a single line became the floor for all my later analysis and modeling.