Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@misterhay
Created September 11, 2019 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterhay/03a3305b6edaf3ff2dc35fdcc9c24990 to your computer and use it in GitHub Desktop.
Save misterhay/03a3305b6edaf3ff2dc35fdcc9c24990 to your computer and use it in GitHub Desktop.
Generate a frequency (equal tempered) of musical notes chart using Pandas
import pandas as pd
noteList = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
def generateOctave(note, startingFrequency):
frequencyList = [startingFrequency]
for x in range(1,9):
frequencyList.append(startingFrequency * 2**x) # each octave up is twice the previous frequency
frequencyDf = pd.DataFrame({note:frequencyList})
return frequencyDf
df = pd.DataFrame() # create an empty dataframe
for n, note in enumerate(noteList, start=1):
startingFrequency = 2**(n/12) * 15.434 # calculate the new note's frequency
frequencyDf = generateOctave(note, startingFrequency)
df = pd.concat([df, frequencyDf], axis=1) # join the new column to the dataframe
df.style.set_precision(4) # display the dataframe with 4 significant figures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment