I have these 3 variables (list of list, except for distance):
unique_pitch_result =
[[0, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64], # len is dynamic
[0, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58],
[0, 43, 44, 45, 46, 47, 48, 49, 50]]
pitch_class_result =
[['0', 'F3', 'F#3 / Gb3', 'G3', 'G#3 / Ab3', 'A3', 'A#3 / Bb3', 'B3', 'C4', 'C#4 / Db4', 'D4', 'D#4 / Eb4', 'E4'],
['0', 'C3', 'C#3 / Db3', 'D3', 'E3', 'F3', 'F#3 / Gb3', 'G3', 'G#3 / Ab3', 'A3', 'A#3 / Bb3'],
['0', 'G2', 'G#2 / Ab2', 'A2', 'A#2 / Bb2', 'B2', 'C3', 'C#3 / Db3', 'D3']]
distance_result =
[2020.0, 611.0, 1782.0]
song_number = 3
I want to insert them per row into a DataFrame using this code:
import pandas as pd
def make_dataframe(unique_pitch_result, pitch_class_result, distance_result, song_number):
print(song_number)
df = pd.DataFrame(columns=('unique-pitch', 'pitch-class', 'distance'))
for i in range(song_number):
df.loc[i] = pd.Series({'unique-pitch': unique_pitch_result, 'pitch-class': pitch_class_result, 'distance': distance_result})
return df
I am hoping to get this result:
unique-pitch pitch-class distance
0 [0, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64] ['0', 'F3', 'F#3/Gb3', 'G3', 'G#3/Ab3', 'A3', 'A#3/Bb3', 'B3', 'C4', 'C#4/Db4', 'D4', 'D#4/Eb4', 'E4'] 2020.0
1 [0, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58] ['0', 'C3', 'C#3/Db3', 'D3', 'E3', 'F3', 'F#3/Gb3', 'G3', 'G#3/Ab3', 'A3', 'A#3/Bb3'] 611.0
2 [0, 43, 44, 45, 46, 47, 48, 49, 50] ['0', 'G2', 'G#2/Ab2', 'A2', 'A#2/Bb2', 'B2', 'C3', 'C#3/Db3', 'D3'] 1782.0
But instead I got this:
unique-pitch ... distance
0 [[0, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 6... ... [2020.0, 611.0, 1782.0]
1 [[0, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 6... ... [2020.0, 611.0, 1782.0]
2 [[0, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 6... ... [2020.0, 611.0, 1782.0]
How should I fix the function make_dataframe?