Created
September 11, 2019 20:08
-
-
Save misterhay/03a3305b6edaf3ff2dc35fdcc9c24990 to your computer and use it in GitHub Desktop.
Generate a frequency (equal tempered) of musical notes chart using Pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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