Chapter 7: Statistics of Sound
7.1 Music as Data
Think of a melody as numbers: pitch, duration, timbre. Simple statistics reveal style and structure.
# Example melody in MIDI pitches
melody_pitches = [60, 62, 64, 65, 67, 65, 64, 62, 60, 64, 67, 72]
melody_pitches7.2 Music Analysis with Pandas and Python
Spreadsheets are just tables: every row describes one song, every column stores the same kind of fact for each song (tempo, key, energy, …).
Why is that powerful?
- Consistency → quick math Uniform columns let us sort, filter, and average in a single line of code.
- Clarity → better questions Well-labeled tables make patterns jump out: which keys dominate? How fast is the typical Miles Davis tune?
- Automation → scale The Pandas library treats a CSV file like a programmable spreadsheet, so the same analysis works on twenty songs or twenty-thousand.
In the table below each row is a jazz classic; the columns capture five numeric (quantitative: countable values) or categorical (qualitative: descriptive categories) features:
- Title: song name (categorical)
- Artist: performer or ensemble (categorical)
- Tempo: beats per minute (numeric)
- Key: tonal center (categorical)
- Energy: 0 to 1 proxy for loudness, density, rhythmic drive (numeric)
You’ll compute summary stats and build three quick plots:
- Histogram of tempo: see how fast most tunes sit.
- Scatter of tempo vs energy: spot the tunes that break the fast-equals-intense rule.
- Box-plot of tempo by key: and a lesson in what happens when most keys hold a single song.
By the end you’ll have a repeatable workflow: tabular data → Pandas → visual insight.
One honest label before we start: this table is hand-built teaching data, and the handwritten card in this chapter's video makes the point visually: someone wrote these numbers down, and that someone was me. The tempos and keys are close to common performance practice, though recordings vary, and Energy is my own 0-to-1 score of how intense each track feels, not a measurement taken from audio. Real datasets arrive with choices like these baked in, usually undocumented; ours documents them. Two spelling notes: keys are written ASCII-style (Eb for E flat) because CSV files and chart labels are happier without the flat glyph, and minor keys carry an m (Dm), with modal tunes listed by their tonal center.
Continue reading this chapter
You're reading a free preview. Purchase the book to unlock every chapter in Artificial Intelligence for Musicians.
Want a hand with the code or building your own setup?
I'm an AI/ML engineer and a professional musician. Bring a question, a real project, a tool you wish existed, or a workflow that's eating your time, and we'll build it on your machine with your files. First call is free, 15 minutes, no commitment.
Book a free 15 minute call →